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

Added function to disable template rendering abort on error #109

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

kabukky
Copy link

@kabukky kabukky commented Mar 4, 2019

We are currently evaluating Jet for our projects.

One thing that is different from a lot of other template languages (e. g. Handlebars) is how Jet handles expressions that cannot be evaluated.

E. g. accessing a non-valid field value will lead to the whole template rendering process being aborted and the error being returned. Handlebars would just insert an empty string into the place of the expression.

To enable this "Handlebars"-like behavior with Jet, I've added the abortTemplateOnError global variable that can be set from the outside via SetAbortTemplateOnError.

It works well with this template (document.yada is not set in this case, the if comparison is also not valid):

{{ document.title }}
{{ document.yada }}
{{ if "2006" < 2018 }}foooooooo{{end}}
{{ document.title }}

Do you see any problems with this? Node.errorf is used in a lot of other situations that I haven't checked yet

Hagelstein, Kai and others added 14 commits March 14, 2019 11:41
make Ranger return interface{}, not reflect.Value
fix isset call with chain node argument
support interface{} values in len()
isset: return false when value is nil
isset: only check for nil on values that can be nil
make notNil a top-level function
When recovering from a panic, the runtime (state) was put back into the state pool.
The state was then re-used by the next template execution.
This led to the pre-crash-context (e. g. variables set on the state via Runtime.Set) being leaked into the next template execution.
@jhsx
Copy link
Member

jhsx commented Jul 28, 2019

Hi, @kabukky thanks for the contribution, can you send multiple pull requests ?
Walking through the pull request i see many modifications unrelated with the meaning of the title of this pull request, this makes hard to evaluate and accept your pull request.

@kabukky
Copy link
Author

kabukky commented Jul 29, 2019

Hi @jhsx Sorry, my master has diverged quite a bit by now.

The relevant changes are all in this commit:
kabukky@b2a337d

I'm still not sure if this is feasible, since it might have side effects. What is your take on it?

Kai Hagelstein and others added 3 commits August 2, 2019 16:36
Changed how the state is reset after previous usage
give better out-of-range error message in index expression evaluation
@annismckenzie
Copy link
Member

Can you pull out kabukky@b2a337d into a new PR?

@tooolbox
Copy link
Contributor

tooolbox commented Jul 1, 2020

@kabukky I believe this was handled with #152 but please chime in if it doesn't fit the use case somehow.

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.

4 participants