diff --git a/config/expr_lex.go b/config/expr_lex.go index b54a14af8..9c9d45e16 100644 --- a/config/expr_lex.go +++ b/config/expr_lex.go @@ -2,6 +2,7 @@ package config import ( "bytes" + "fmt" "log" "unicode" "unicode/utf8" @@ -13,6 +14,8 @@ const lexEOF = 0 // The parser uses the type Lex as a lexer. It must provide // the methods Lex(*SymType) int and Error(string). type exprLex struct { + Err error + input string pos int width int @@ -127,5 +130,5 @@ func (x *exprLex) backup() { // The parser calls this method on a parse error. func (x *exprLex) Error(s string) { - log.Printf("parse error: %s", s) + x.Err = fmt.Errorf("parse error: %s", s) } diff --git a/config/expr_parse.go b/config/expr_parse.go index 0ffb0ba14..bfb81c6fb 100644 --- a/config/expr_parse.go +++ b/config/expr_parse.go @@ -21,12 +21,18 @@ func ExprParse(v string) (Interpolation, error) { exprResult = nil // Parse - exprParse(&exprLex{input: v}) + lex := &exprLex{input: v} + exprParse(lex) // Build up the errors var err error + if lex.Err != nil { + err = multierror.ErrorAppend(err, lex.Err) + } if len(exprErrors) > 0 { - err = &multierror.Error{Errors: exprErrors} + err = multierror.ErrorAppend(err, exprErrors...) + } + if err != nil { exprResult = nil }