defstudio / telegraph

Telegraph is a Laravel package for fluently interacting with Telegram Bots
MIT License
697 stars 118 forks source link

JsonException Syntax error when loading not existing storage key #415

Closed MatteoGheza closed 1 year ago

MatteoGheza commented 1 year ago

In a webapp I'm developing, I found this error:

JsonException Syntax error on /vendor/defstudio/telegraph/src/Storage/FileStorageDriver.php in json_decode at line 39

/** @phpstan-ignore-next-line */
return rescue(fn () => json_decode($json, true, flags: JSON_THROW_ON_ERROR), []);
} catch (JsonException|FileNotFoundException) {

Why is the catch block not working? After throwing this error (into the webhook controller file) the bot didn't reply to the message, the execution stopped.

After enabling debug logs, I saw this warning:

json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in REDACTED/vendor/defstudio/telegraph/src/Storage/FileStorageDriver.php on line 39

This was triggered by calling

$this->message->from()->storage()->get('user', null);
MatteoGheza commented 1 year ago

It should be a Sentry bug... It's configured to log that exception even if it's expected. After ignoring it from config, everything was working fine again.