Skip to content

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

@rsc

Description

@rsc
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions