-
-
Notifications
You must be signed in to change notification settings - Fork 237
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Exposing originalError in LiquidError #742
Labels
Comments
Could import { Liquid, Tag, LiquidError } from "liquidjs";
class AssertTagAssertionError extends LiquidError {
errorCode;
constructor(err, errorCode, token) {
super(err, token);
this.errorCode = errorCode;
}
}
class AssertTag extends Tag {
constructor(token, remainTokens, liquid) {
super(token, remainTokens, liquid);
// Argument parsing omitted.
}
*render(ctx, emitter) {
// Always throw, for demonstration purposes.
throw new AssertTagAssertionError("something went wrong", 400, this.token);
}
}
const liquid = new Liquid();
liquid.registerTag("assert", AssertTag);
liquid.parseAndRender("{% assert foo %}").catch((e) => {
if (e instanceof AssertTagAssertionError) {
console.error(e.message, e.errorCode);
} else {
throw e;
}
}); output
|
harttle
added a commit
that referenced
this issue
Aug 29, 2024
harttle
added a commit
that referenced
this issue
Aug 29, 2024
harttle
added a commit
that referenced
this issue
Aug 29, 2024
github-actions bot
pushed a commit
that referenced
this issue
Aug 29, 2024
## [10.16.6](v10.16.5...v10.16.6) (2024-08-29) ### Bug Fixes * expose originalError from LiquidError, [#742](#742) ([86f6bf0](86f6bf0))
yes this would be perfect |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Hi, in a recent project I'm using liquidjs heavily and this is one of the scenarios that I'm dealing with, I have custom tags and I need to stop render process if some rule breaking errors occur, I have a custom assert tag:
Now, I need any further rendering to stop if condition is falsy also I need to inform the code that called render that what went wrong, so one very intuitive way is to throw a custom error in the assert tag
and in the render:
right now the
parseAndRende
r only returnsRenderError
andoriginalError
while present is protected and private and we don't have access to it in the catch block, we could write a special error code in the message and use that, but it is far from elegant, please provide a way to throw custom known Error types in filters and tags and drops, and catch and identify them when calling render function, thanksif this is approved and you would like a PR please tell me I'm more than happy to make the changes
The text was updated successfully, but these errors were encountered: