From 9ec372674584c8b357bd1adb66632a7ab164093c Mon Sep 17 00:00:00 2001 From: bencroker Date: Tue, 10 Dec 2024 08:07:02 -0600 Subject: [PATCH] Catch and log exceptions in local generator script --- CHANGELOG.md | 6 ++++++ composer.json | 2 +- src/drivers/generators/LocalGenerator.php | 3 ++- src/drivers/generators/local-generator-script.php | 9 ++++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 223ecbce..8fff9676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Release Notes for Blitz +## 5.9.8 - 2024-12-10 + +### Changed + +- The logs now output the reason why pages failed to be generated using the Local Generator with debug mode enabled ([#737](https://github.com/putyourlightson/craft-blitz/issues/737)). + ## 5.9.7 - 2024-12-06 ### Changed diff --git a/composer.json b/composer.json index c0cb6c7a..1af50b73 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": "5.9.7", + "version": "5.9.8", "type": "craft-plugin", "homepage": "https://putyourlightson.com/plugins/blitz", "license": "proprietary", diff --git a/src/drivers/generators/LocalGenerator.php b/src/drivers/generators/LocalGenerator.php index c416eb07..9992fe86 100644 --- a/src/drivers/generators/LocalGenerator.php +++ b/src/drivers/generators/LocalGenerator.php @@ -86,12 +86,13 @@ public function generateUrisWithProgress(array $siteUris, callable $setProgressH $this->outputVerbose($url, false); }); + $result = false; + try { $context->send($config); $result = $context->receive($canceller); } catch (Throwable $exception) { Blitz::$plugin->debug($exception->getMessage(), [], $url); - $result = false; } $canceller->unsubscribe($cancellerId); diff --git a/src/drivers/generators/local-generator-script.php b/src/drivers/generators/local-generator-script.php index 9c608845..b5eef34c 100755 --- a/src/drivers/generators/local-generator-script.php +++ b/src/drivers/generators/local-generator-script.php @@ -6,6 +6,7 @@ use Amp\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 a error was encountered: ' . $exception->getMessage(); + Blitz::$plugin->debug($error, [], $url); + } $channel->send($success); };