1
0
mirror of https://github.com/golang/go synced 2024-11-24 09:00:13 -07:00

html/template, text/template: drop defined template list from errors

The report in #17414 points out that if you have many many templates,
then this is an overwhelming list and just hurts the signal-to-noise ratio of the error.

Even the test of the old behavior also supports the idea that this is noise:

	template: empty: "empty" is an incomplete or empty template; defined templates are: "secondary"

The chance that someone mistyped "secondary" as "empty" is slim at best.

Similarly, the compiler does not augment an error like 'unknown variable x'
by dumping the full list of all the known variables.

For all these reasons, drop the list.

Fixes #17414.

Change-Id: I78f92d2c591df7218385fe723a4abc497913acf8
Reviewed-on: https://go-review.googlesource.com/32116
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Russ Cox 2016-10-26 13:12:17 -04:00
parent 54f691d69d
commit ef3a9f2dd4
3 changed files with 3 additions and 3 deletions

View File

@ -96,7 +96,7 @@ func (t *Template) escape() error {
t.nameSpace.escaped = true
if t.escapeErr == nil {
if t.Tree == nil {
return fmt.Errorf("template: %q is an incomplete or empty template%s", t.Name(), t.DefinedTemplates())
return fmt.Errorf("template: %q is an incomplete or empty template", t.Name())
}
if err := escapeTemplate(t, t.text.Root, t.Name()); err != nil {
return err

View File

@ -190,7 +190,7 @@ func (t *Template) execute(wr io.Writer, data interface{}) (err error) {
vars: []variable{{"$", value}},
}
if t.Tree == nil || t.Root == nil {
state.errorf("%q is an incomplete or empty template%s", t.Name(), t.DefinedTemplates())
state.errorf("%q is an incomplete or empty template", t.Name())
}
state.walk(value, t.Root)
return

View File

@ -932,7 +932,7 @@ func TestMessageForExecuteEmpty(t *testing.T) {
t.Fatal("expected second error")
}
got = err.Error()
want = `template: empty: "empty" is an incomplete or empty template; defined templates are: "secondary"`
want = `template: empty: "empty" is an incomplete or empty template`
if got != want {
t.Errorf("expected error %s got %s", want, got)
}