-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
text/template: give position info on error #3188
Labels
Milestone
Comments
Labels changed: added priority-later, packagechange, removed priority-triage. Owner changed to @robpike. Status changed to Accepted. |
I took a look at this and have a proposal to include filename (if available) and column number for template errors. Example: _, err := template.New("foo").Parse(` {{if $foo}}{{end}} `) Current error: template: foo:3: undefined variable "$foo" New error: template: foo:3:14 undefined variable "$foo" For this, errorf now also accepts an argument for the input offset (taken from item.pos), and the template filename is stored for debug purposes when available. My plan is to remove lex.lineNumber() and rely only on item.pos for error messages. Please let me know if it is acceptable: http://golang.org/cl/6442067 Note: I only implemented it in parse.useVar, so if you think it looks good I can extend to the rest of the package. |
Updated with a full implementation: all errors display line/column numbers of the related token and, when available, the filename. http://golang.org/cl/6442067 |
A new patch added position info to all exec errors as well. Because this replaces the Line field from nodes by a Pos field with scanner.Position, this is not backwards compatible anymore (and broke html/template), I realized later. I'll review this and make it fully compatible, keeping existing fields and using a method for the position info. Sorry for the comment spam. :P |
As explained in http://golang.org/doc/contribute.html, we prefer to discuss significant changes by e-mail before sending code, let alone submitting a code review through the issue reporting channel. Please start a conversation in the regular forum to discuss what you'd like to do. Once we have design we're happy with we can move to reviewing code. -rob |
This issue was closed by revision 7f4b4c0. 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.
The text was updated successfully, but these errors were encountered: