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

More forgiving errors during dev with missing filters #3386

Closed
LeaVerou opened this issue Jul 28, 2024 · 2 comments
Closed

More forgiving errors during dev with missing filters #3386

LeaVerou opened this issue Jul 28, 2024 · 2 comments
Labels
enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.

Comments

@LeaVerou
Copy link

LeaVerou commented Jul 28, 2024

I’ve been using filters extensively. Most of my 11ty projects have an import like:

import * as filters from "./filters/index.js";

and a mass-add statement in the config:

for (let name in filters) {
	config.addFilter(name, filters[name]);
}

If a filter is invalid, 11ty currently throws (and the error message code path is broken, see #3385).
I’d argue that this is not a reason for complete and total failure — a warning should suffice. Something like "Filter foo ignored, as it is not a function".

However, then if filter foo is used anywhere, that would throw. But should it really?

As part of debugging, I often comment out plugins. But that means now their filters produce errors! So temporarily disabling a plugin involves tediously adding stubs like

config.addFilter("foo", content => content);

What if 11ty could do this for any unrecognized filter, and just printed out a warning? Fault tolerance and robustness are generally good API design principles to follow. The main case where you don't want to fail gracefully is when making the wrong assumption could produce data loss (see #3373), but that doesn’t seem to be the case here.

@LeaVerou LeaVerou changed the title Better ergonomics around filter usage (robustness & aggregation) More robust filter definition & usage Jul 28, 2024
@zachleat
Copy link
Member

I bet we could get away with a template-syntax independent implementation of this feature using Proxy. I’d imagine folks might want it to operate this way during dev but not in a full production build, too.

@zachleat zachleat added the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Jul 30, 2024
@zachleat
Copy link
Member

By default this repo closes enhancement request issues and places them in a queue for folks to upvote. We do this to avoid a large build-up of open issues. We got this idea from the lodash project.

Don’t forget to upvote the first comment with 👍 to register your vote! You can view the current enhancement backlog.

@zachleat zachleat closed this as not planned Won't fix, can't repro, duplicate, stale Jul 30, 2024
@zachleat zachleat changed the title More robust filter definition & usage More forgiving errors during dev with missing filters Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved.
Projects
None yet
Development

No branches or pull requests

2 participants