Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show exception messages in build output when fork is installed #159

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

imacrayon
Copy link
Contributor

@imacrayon imacrayon commented Jan 27, 2024

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.

@imacrayon imacrayon changed the title Show exception messages in built output Show exception messages in build output Feb 11, 2024
@jasonvarga
Copy link
Member

Apologies for the delay.

On the main branch, I'm throwing an exception manually from 2 pages. It seems to work fine:

if (in_array($this->data->slug(), ['page-3', 'page-6'])) {
    throw new \Exception('Page 3 and 6 dont work.');
}

CleanShot 2024-09-25 at 14 21 41

When I set 'failures' to 'errors', it fails immediately with the proper exit code after the first error:

CleanShot 2024-09-25 at 14 22 15

I must be misunderstanding the issue, would you mind clarifying?

@imacrayon
Copy link
Contributor Author

Hey, no worries, I honestly forgot I submitted this lol

So I ran a quick test and it looks like the output I'm getting is because I'm using spatie/fork. If I remove fork I get output like your screenshot.

@jasonvarga
Copy link
Member

I don't see a difference with or without fork. Weird. 🤔

@jasonvarga
Copy link
Member

Nevermind, I can confirm what you're saying! I must have been testing on the wrong branch. 😊

On master, without fork:

CleanShot 2024-09-25 at 15 20 30

On master, with fork:

CleanShot 2024-09-25 at 15 22 29

@jasonvarga jasonvarga changed the title Show exception messages in build output Show exception messages in build output when fork is installed Sep 25, 2024
@jasonvarga jasonvarga merged commit 535697a into statamic:master Sep 25, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants