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

Error stack improvements #3572

Merged
merged 6 commits into from
Dec 11, 2024
Merged

Conversation

noelforte
Copy link
Contributor

@noelforte noelforte commented Dec 6, 2024

Caught an issue while working to improve errors in eleventy-plugin-vento. Looks like EleventyErrorHandler's log function loop was assigning to nextRef instead of the originalError key, leading to errors like this:

{% shortcodeThatThrowsAnError %} <!-- => new Error(...) -->
[11ty] Problem writing Eleventy templates:
[11ty] 1. Having trouble rendering njk template ./src/nunjucks.njk (via TemplateContentRenderError)
[11ty] 2. throws an error

instead of

[11ty] Problem writing Eleventy templates:
[11ty] 1. Having trouble rendering njk template ./src/nunjucks.njk (via TemplateContentRenderError)
[11ty] 2. (./src/nunjucks.njk)
[11ty]   EleventyNunjucksError: Error with Nunjucks shortcode `errorThrow` (via Template render error)
[11ty] 3. throws an error

As a related fix, I also added support for the error handler to unwrap cause from the Error object if it's defined, even if cause.originalError doesn't exist. This will be helpful for custom languages like Vento, which attach more errors to the stack via the Error.cause convention.

Would be great to have this in 3.0.1!

(related: noelforte/eleventy-plugin-vento#69)

replace unformatted, escaped string output from util.inspect with
debug's own `%O` object pretty-print
…Ref`

and handle cases when `.originalError` is undefined, but `cause` exists
@noelforte noelforte force-pushed the error-stack-improvements branch from 50b7f34 to e6368f8 Compare December 6, 2024 22:30
zachleat
zachleat previously approved these changes Dec 11, 2024
@zachleat zachleat merged commit 41dbedc into 11ty:main Dec 11, 2024
11 checks passed
@zachleat
Copy link
Member

This will ship with v3.0.1-alpha.1 thank you!

@noelforte noelforte deleted the error-stack-improvements branch December 12, 2024 08:02
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.

3 participants