Skip to content

Commit

Permalink
improves clarity of unknown identifier error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Dec 3, 2018
1 parent 36115f4 commit e81b003
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (c *compiler) compile() (string, error) {
if c.curStmt != nil {
s = c.curStmt
}
return "", errors.WithStack(errors.Wrapf(err, "line %d", s.T().LineNumber))
return "", errors.WithStack(errors.Errorf("line %d: %s", s.T().LineNumber, err))
}

c.write(bb, res)
Expand Down Expand Up @@ -131,7 +131,7 @@ func (c *compiler) evalAssignExpression(node *ast.AssignExpression) (interface{}
}
n := node.Name.Value
if !c.ctx.Has(n) {
return nil, errors.Errorf("could not find identifier named %s", n)
return nil, errors.Wrap(ErrUnknownIdentifier, fmt.Sprintf("%q", n))
}
c.ctx.Set(n, v)
return nil, nil
Expand Down Expand Up @@ -307,7 +307,7 @@ func (c *compiler) evalIdentifier(node *ast.Identifier) (interface{}, error) {
if node.Value == "nil" {
return nil, nil
}
return nil, errors.Wrap(ErrUnknownIdentifier, node.Value)
return nil, errors.Wrap(ErrUnknownIdentifier, fmt.Sprintf("%q", node.Value))
}

func (c *compiler) evalInfixExpression(node *ast.InfixExpression) (interface{}, error) {
Expand Down
3 changes: 1 addition & 2 deletions plush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package plush
import (
"testing"

"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -148,7 +147,7 @@ func Test_UndefinedArg(t *testing.T) {

_, err := Render(input, ctx)
r.Error(err)
r.Equal(ErrUnknownIdentifier, errors.Cause(err))
r.Equal(`line 1: "bar": unknown identifier`, err.Error())
}

// func Test_FizzParses(t *testing.T) {
Expand Down

0 comments on commit e81b003

Please sign in to comment.