mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
config: don't crash when there is an error parsing interpolation
[GH-282]
This commit is contained in:
parent
62e2743dcc
commit
ffcacca191
@ -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 <prefix>Lex as a lexer. It must provide
|
||||
// the methods Lex(*<prefix>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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user