statamic / ssg

The official Statamic Static Site Generator
229 stars 23 forks source link

Show exception messages in build output #159

Open imacrayon opened 5 months ago

imacrayon commented 5 months ago

This PR prevents exception messages from being swallowed by build tasks.

My SSG config is set to fail on errors:

// config/statamic/ssg.php

'failures' => 'errors',

I ran into a situation today where my build started failing and the the only console output I got was:

[✔] Gathered content to be generated

Static site generation failed.

After digging in I found that any GenerationFailedException thrown inside a build task's closure is ignored and only the closure's return value is captured by the calling method.

I updated the task closures so that they will now return an exception message instead of throwing, then the calling method (createContentFiles), will check for an exception message in the results and throw an exception from outside a task loop.

With this change the build output will now appear like this:

[✔] Gathered content to be generated
[✘] /page (Exception message here)
Static site generation failed.