Skip to content

text/template: misleading error in template: "nil pointer" on typo #15125

@boslandm

Description

@boslandm

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go1.6

  1. What operating system and processor architecture are you using (go env)?

Playground, also reproduced on
GOHOSTARCH="amd64"
GOHOSTOS="linux"

  1. What did you do?
    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

  1. What did you expect to see?

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.

  1. 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 {}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions