-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
html/template: Execute panics on custom function errors after Clone #5980
Labels
Milestone
Comments
It turns out that all errors that occur during template execution suffer from this bug. For example, if you add an argument to the myFunc function call in the playground example you also get the same problem: const tmplString = `{{myFunc "arg1"}}` I am currently considering, as a partial workaround, to create wrappers for all custom functions that start panicking on any returned errors. For example, if you rewrite myFunc in the go playground example as follows, then the error is returned: func myFunc() (string, error) { panic(fmt.Errorf("My error!")) } Anyone a better idea? This works for custom functions, but of course not for errors that occur in the template itself. |
The problem is that text/template/parse's Tree.text wasn't getting copied during the clone. Unfortunately, I don't see any way to fix this without adding to the public API. Proposed fix in https://golang.org/cl/12420044 |
This issue was closed by revision eeb7585. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by pavadeli:
The text was updated successfully, but these errors were encountered: