You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A type has definite members. If a member is being requested that does not exist for that type the template should return a no type found error, even if the value of the type is nil.
What did you see instead?
Executing a template with a typo on a nil struct gives the misleading error that the struct is nil. This is true but the real error is that no member can be found.
template: tmpl:1:2: executing "tmpl" at <.Get>: nil pointer evaluating *main.outer.Get
template: tmpl:1:2: executing "tmpl" at <.Get>: Get is not a field of struct type struct {}
The text was updated successfully, but these errors were encountered:
bradfitz
changed the title
Misleading error in template: "nil pointer" on typo
text/template: misleading error in template: "nil pointer" on typo
Apr 7, 2016
When evaluating "{{.MissingField}}" on a nil *T, Exec returns
"can't evaluate field MissingField in type *T" instead of
"nil pointer evaluating *T.MissingField".
Fixesgolang/go#15125
Change-Id: I6e73f61b8a72c694179c1f8cdc808766c90b6f57
Reviewed-on: https://go-review.googlesource.com/21705
Reviewed-by: Rob Pike <r@golang.org>
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Please answer these questions before submitting your issue. Thanks!
go version
)?go1.6
go env
)?Playground, also reproduced on
GOHOSTARCH="amd64"
GOHOSTOS="linux"
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
http://play.golang.org/p/fjDUgnco1F
A type has definite members. If a member is being requested that does not exist for that type the template should return a no type found error, even if the value of the type is nil.
Executing a template with a typo on a nil struct gives the misleading error that the struct is nil. This is true but the real error is that no member can be found.
template: tmpl:1:2: executing "tmpl" at <.Get>: nil pointer evaluating *main.outer.Get
template: tmpl:1:2: executing "tmpl" at <.Get>: Get is not a field of struct type struct {}
The text was updated successfully, but these errors were encountered: