From 2152c40e5f22176787ff0bcf05b6a611869135a3 Mon Sep 17 00:00:00 2001 From: bencroker Date: Tue, 10 Dec 2024 08:14:58 -0600 Subject: [PATCH] Catch and log exceptions in local generator script --- CHANGELOG.md | 8 +++++++- composer.json | 2 +- src/drivers/generators/local-generator-script.php | 9 ++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aeaa00dc..f1583b08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,17 @@ # Release Notes for Blitz +## 4.23.9 - 2024-12-10 + +### Changed + +- The reasons why pages failed to be generated using the Local Generator are now logged when debug mode is enabled ([#737](https://github.com/putyourlightson/craft-blitz/issues/737)). + ## 4.23.8 - 2024-12-06 ### Changed - More deployer settings are now redacted when generating a diagnostics report. -- The existence of cached files is checked before deletion, to prevent unnecessarily logged warnings ([#741](https://github.com/putyourlightson/craft-blitz/issues/741)). +- The existence of cached files is now checked before deletion, to prevent unnecessarily logged warnings ([#741](https://github.com/putyourlightson/craft-blitz/issues/741)). - The `injectScriptEvent` variable is no longer defined in the global scope, for better compatibility with JavaScript libraries ([#747](https://github.com/putyourlightson/craft-blitz/issues/747)). ## 4.23.7 - 2024-11-15 diff --git a/composer.json b/composer.json index 4eaa4b72..a01d55cf 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "putyourlightson/craft-blitz", "description": "Intelligent static page caching for creating lightning-fast sites.", - "version": "4.23.8", + "version": "4.23.9", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/drivers/generators/local-generator-script.php b/src/drivers/generators/local-generator-script.php index 4b60b249..c33d20f1 100755 --- a/src/drivers/generators/local-generator-script.php +++ b/src/drivers/generators/local-generator-script.php @@ -6,6 +6,7 @@ use Amp\Parallel\Sync\Channel; use craft\services\Plugins; use craft\web\View; +use putyourlightson\blitz\Blitz; use yii\base\Event; /** @@ -98,8 +99,14 @@ function() { * @var craft\web\Application $app */ $app = require $root . '/vendor/craftcms/cms/bootstrap/web.php'; + $success = false; - $success = $app->run() === 0; + try { + $success = $app->run() == 0; + } catch (Throwable $exception) { + $error = 'Page not cached because an error was encountered: ' . $exception->getMessage(); + Blitz::$plugin->debug($error, [], $url); + } yield $channel->send($success); };