diff --git a/src/Wallabag/CoreBundle/Helper/FileCookieJar.php b/src/Wallabag/CoreBundle/Helper/FileCookieJar.php index 52c7f5deb..9a63e9493 100644 --- a/src/Wallabag/CoreBundle/Helper/FileCookieJar.php +++ b/src/Wallabag/CoreBundle/Helper/FileCookieJar.php @@ -5,6 +5,7 @@ namespace Wallabag\CoreBundle\Helper; use GuzzleHttp\Cookie\FileCookieJar as BaseFileCookieJar; use GuzzleHttp\Cookie\SetCookie; use GuzzleHttp\Utils; +use Psr\Log\LoggerInterface; /** * Overidden Cookie behavior to: @@ -13,6 +14,19 @@ use GuzzleHttp\Utils; */ class FileCookieJar extends BaseFileCookieJar { + private $logger; + + /** + * @param LoggerInterface $logger Only used to log info when something goes wrong + * @param string $cookieFile File to store the cookie data + */ + public function __construct(LoggerInterface $logger, $cookieFile) + { + parent::__construct($cookieFile); + + $this->logger = $logger; + } + /** * Saves the cookies to a file. * @@ -57,6 +71,11 @@ class FileCookieJar extends BaseFileCookieJar try { $data = Utils::jsonDecode($json, true); } catch (\InvalidArgumentException $e) { + $this->logger->error('JSON inside the cookie is broken', [ + 'json' => $json, + 'error_msg' => $e->getMessage(), + ]); + // cookie file is invalid, just ignore the exception and it'll reset the whole cookie file $data = ''; } diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 169b67e5c..3f3d4de71 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml @@ -83,7 +83,9 @@ services: wallabag_core.guzzle.cookie_jar: class: Wallabag\CoreBundle\Helper\FileCookieJar - arguments: ["%kernel.cache_dir%/cookiejar.json"] + arguments: + - "@logger" + - "%kernel.cache_dir%/cookiejar.json" wallabag_core.content_proxy: class: Wallabag\CoreBundle\Helper\ContentProxy