]> Cypherpunks repositories - gostls13.git/commitdiff
text/template/parse: don't show itemType in error messages
authorShenghou Ma <minux.ma@gmail.com>
Mon, 21 Jan 2013 18:48:40 +0000 (02:48 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Mon, 21 Jan 2013 18:48:40 +0000 (02:48 +0800)
so that the user don't need to decipher something like this:
template: main:1: expected %!s(parse.itemType=14) in end; got "|"
now they get this:
template: main:1: unexpected "|" in end

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7128054

src/pkg/text/template/parse/parse.go

index 250cad5f353be122e46b9477c5db47cef42cfddf..c0fb9274a3d584e2697defca82186f1b01a1ab21 100644 (file)
@@ -151,7 +151,7 @@ func (t *Tree) error(err error) {
 func (t *Tree) expect(expected itemType, context string) item {
        token := t.nextNonSpace()
        if token.typ != expected {
-               t.errorf("expected %s in %s; got %s", expected, context, token)
+               t.unexpected(token, context)
        }
        return token
 }
@@ -160,7 +160,7 @@ func (t *Tree) expect(expected itemType, context string) item {
 func (t *Tree) expectOneOf(expected1, expected2 itemType, context string) item {
        token := t.nextNonSpace()
        if token.typ != expected1 && token.typ != expected2 {
-               t.errorf("expected %s or %s in %s; got %s", expected1, expected2, context, token)
+               t.unexpected(token, context)
        }
        return token
 }