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

Add an Eleventy event that fires after errors #3500

Open
kfranqueiro opened this issue Oct 22, 2024 · 4 comments
Open

Add an Eleventy event that fires after errors #3500

kfranqueiro opened this issue Oct 22, 2024 · 4 comments
Labels
enhancement feature: 🛠 configuration Related to Eleventy’s Configuration file

Comments

@kfranqueiro
Copy link

Is your feature request related to a problem? Please describe.

I found out today that eleventy.after only runs after successful builds; if an error occurs, it doesn't run. This is problematic for customizations that need to perform cleanup whether the build succeeds or not.

Describe the solution you'd like

I presume we wouldn't want to alter the existing behavior of eleventy.after. Can we add an eleventy.afterError or something?

Describe alternatives you've considered

I'm not aware if there's any other way of handling error cases from within eleventy.config.js. Writing a wrapper around the entire build invocation is problematic, especially if it needs access to variables set up inside the config function.

Additional context

No response

@zachleat zachleat added the feature: 🛠 configuration Related to Eleventy’s Configuration file label Oct 23, 2024
@zachleat
Copy link
Member

maybe eleventy.finally after try/catch/finally?

@Ryuno-Ki
Copy link
Contributor

I feel like a JavaScript~y way would be eleventy.onerror. An eleventy.finally could also be useful in case of cleaning up (file handler, database connections or what-have-you)

@kfranqueiro
Copy link
Author

kfranqueiro commented Oct 23, 2024

If it were named eleventy.finally I'd expect it to fire both on success and failure, which would be fine for my current case, but I wonder if folks might have use cases specifically for failure as well.

eleventy.error could be fine for that, but I would vote against eleventy.onerror specifically as that would cause redundant "on" (eleventyConfig.on("eleventy.onerror")) which is not the way DOM APIs work (e.g. addEventListener("click") not addEventListener("onclick")).

@Ryuno-Ki
Copy link
Contributor

I was thinking on an eleventyConfig.onerror(callback) but haven't used its Event callbacks before (yet).
From my jQuery days event namespaces already used dots (although I have also seen a convention using colons).

Fine with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature: 🛠 configuration Related to Eleventy’s Configuration file
Projects
None yet
Development

No branches or pull requests

4 participants
@zachleat @kfranqueiro @Ryuno-Ki and others