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

text/template: wrong template name in error message #8577

Closed
rsc opened this issue Aug 23, 2014 · 4 comments
Closed

text/template: wrong template name in error message #8577

rsc opened this issue Aug 23, 2014 · 4 comments
Assignees
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Aug 23, 2014

http://play.golang.org/p/cf0y7Sw9lQ

The error at run time says
html/template:ONE:12: no such template "dummy"
but the reference to dummy is in THREE not ONE.

Full report from mailing list below.



---------- Forwarded message ----------
From: Meester Guy Person <songofchrist@gmail.com>
Date: Fri, Aug 22, 2014 at 2:59 PM
Subject: [golang-dev] Problem with template error reporting
To: golang-dev@googlegroups.com


Hopefully this is the appropriate place to report this.  If not, hope someone will
direct me to where I need to go.

Was fiddling with templates and I noticed that, although the line number reported in a
template error is correct and refers to the specific template in which the error
occurred, the name of the template reported is incorrect.  Here's an example:
http://play.golang.org/p/cf0y7Sw9lQ

You'll notice here that when run, we get the error: html/template:ONE:12: no such
template "dummy".  "dummy" is a reference to a template that does
not exist in the set, so we'd expect this error.  The error is reported as having
occurred on line 12 of template ONE, which is the base template.  In fact, the error
occurs in line 12 of THREE, an embedded template.

So it would make sense if it reported the error as being in the filled version of ONE,
although this would not be terribly helpful.  It would also make sense if it reported
the line number of the template in which the error occurred -- by far the most helpful
behavior.  But we seem to have a mix here that is just confusing.  Looks like a bug to
me.  The error should report the specific template in which the error occurred, not the
first template in the set.
-- 
You received this message because you are subscribed to the Google Groups
"golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 25, 2014

Comment 1 by songofchrist:

Another thought on this. Would it be helpful/possible to implement a template error
trace? So in this example, instead of getting back "THREE:12", might get back something
like "THREE:12:TWO:7:ONE:7", which tells us both where the immediate error occurred as
well as what other templates were called and where prior to the error? Seems like this
might be very useful for debugging.
@robpike
Copy link
Contributor

@robpike robpike commented Aug 26, 2014

Comment 2:

The text/template package gives the correct error:
template: THREE:12:16: executing "THREE" at <{{template "dummy" ....>: template
"dummy" not defined
The problem therefore lies in where/when/how html/template recognizes the error.
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 26, 2014

Comment 3:

CL https://golang.org/cl/130620043 mentions this issue.
@robpike
Copy link
Contributor

@robpike robpike commented Aug 29, 2014

Comment 4:

This issue was closed by revision 1ad1c0b.

Status changed to Fixed.

@rsc rsc added fixed labels Aug 29, 2014
@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
ErrorContext now has all the information it needs from the Node,
rather than depending on the template that contains it. This makes
it easier for html/template to generate correct locations in its
error messages.

Updated html/template to use this ability where it is easy, which is
not everywhere, but more work can probably push it through.

Fixes golang#8577.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/130620043
wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
ErrorContext now has all the information it needs from the Node,
rather than depending on the template that contains it. This makes
it easier for html/template to generate correct locations in its
error messages.

Updated html/template to use this ability where it is easy, which is
not everywhere, but more work can probably push it through.

Fixes golang#8577.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/130620043
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.