Access the list of render errors
See original GitHub issueHi! 👋 This seems like a great library.
We’re using liquid-ruby for our customers to be able to customize some of their templates. We want to use liquidjs to do client-side previews and error parsing, so we can give the customers fast feedback while avoiding a round-trip to our server’s precious resources.
In Ruby liquid, when rendering a template, an array of the errors is available afterwards, which can be used to display to the client. I’ve looked through the docs/repo, and liquidjs seems to behave very differently from liquid-ruby in this way.
Ruby example:
options = options = { strict_variables: true, strict_filters: true }
template = Liquid::Template.parse(markup)
result = template.render(context, options)
# Lots of errors to look at here
template.errors.each do |error|
puts error
end
With the same markup and options as the Ruby version, liquidjs throws one error and quits.
const engine = new Liquid()
const template = engine.parse(markup)
// This throws a single error
const result = engine.renderSync(template, {}, { strictFilters: true, strictVariables: true })
I’m surprised this doesn’t exist yet, but I’m guessing liquidjs is used more for server templates?
Is this possible to do with liquidjs or are we out of luck? Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
An additional method or a
catchAllErrors defaults false
orfailFast defaults true
argument will be better, or this feature will be a breaking change.Great, thank you for confirming my assumptions. If we decide to move forward with the client-side approach, I will see about a PR. It looks like handling errors happens in
renderTemplates
. It seems like that could return an object instead of a string, like{ result: string, errors: LiquidError[] }
. So as not to break the end-user API, therender
function could still return a string, but keep the errors inengine
. Does that seem plausible or am I way off?