From 8f6b1344a92ff8877cf24a5de9177bf7d0a2a187 Mon Sep 17 00:00:00 2001 From: Mikael Olenfalk Date: Mon, 17 Apr 2017 20:02:14 +0200 Subject: [PATCH] Return PosError instead of error in more cases --- hcl/parser/parser.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hcl/parser/parser.go b/hcl/parser/parser.go index b488180..098e1bc 100644 --- a/hcl/parser/parser.go +++ b/hcl/parser/parser.go @@ -197,9 +197,12 @@ func (p *Parser) objectItem() (*ast.ObjectItem, error) { keyStr = append(keyStr, k.Token.Text) } - return nil, fmt.Errorf( - "key '%s' expected start of object ('{') or assignment ('=')", - strings.Join(keyStr, " ")) + return nil, &PosError{ + Pos: p.tok.Pos, + Err: fmt.Errorf( + "key '%s' expected start of object ('{') or assignment ('=')", + strings.Join(keyStr, " ")), + } } // do a look-ahead for line comment @@ -319,7 +322,10 @@ func (p *Parser) objectType() (*ast.ObjectType, error) { // No error, scan and expect the ending to be a brace if tok := p.scan(); tok.Type != token.RBRACE { - return nil, fmt.Errorf("object expected closing RBRACE got: %s", tok.Type) + return nil, &PosError{ + Pos: tok.Pos, + Err: fmt.Errorf("object expected closing RBRACE got: %s", tok.Type), + } } o.List = l