Skip to content

Commit

Permalink
Catch and log exceptions in local generator script
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Dec 10, 2024
1 parent baaca69 commit 9ec3726
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/generators/LocalGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/drivers/generators/local-generator-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Amp\Sync\Channel;
use craft\services\Plugins;
use craft\web\View;
use putyourlightson\blitz\Blitz;
use yii\base\Event;

/**
Expand Down Expand Up @@ -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);
};

0 comments on commit 9ec3726

Please sign in to comment.