Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augment expression parsing error with position #1887

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions pkg/config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"regexp"
"strconv"

"github.com/pkg/errors"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/gocty"
ctyJson "github.com/zclconf/go-cty/cty/json"
Expand Down Expand Up @@ -72,7 +73,7 @@ func importBlueprint(f string) (Blueprint, YamlCtx, error) {
if yep.pos.Line != 0 {
yamlCtx.pathToPos[yPath(path.String())] = yep.pos
}
errs.At(path, fmt.Errorf("YAML parsing error: %s", yep.errMsg))
errs.At(path, errors.New(yep.errMsg))
}
return Blueprint{}, yamlCtx, errs
}
Expand Down Expand Up @@ -152,7 +153,7 @@ func NewYamlCtx(data []byte) (YamlCtx, error) {
if yep.pos.Line != 0 {
m[yPath(path.String())] = yep.pos
}
errs.At(path, fmt.Errorf("YAML parsing error: %s", yep.errMsg))
errs.At(path, errors.New(yep.errMsg))
}
return YamlCtx{m, lines}, errs
}
Expand Down Expand Up @@ -248,7 +249,7 @@ func (y *YamlValue) unmarshalScalar(n *yaml.Node) error {
}
ty, err := gocty.ImpliedType(s)
if err != nil {
return err
return fmt.Errorf("line %d: %w", n.Line, err)
}
if y.v, err = gocty.ToCtyValue(s, ty); err != nil {
return err
Expand All @@ -257,13 +258,15 @@ func (y *YamlValue) unmarshalScalar(n *yaml.Node) error {
if l, is := IsYamlExpressionLiteral(y.v); is { // HCL literal
var e Expression
if e, err = ParseExpression(l); err != nil {
return err
// TODO: point to exact location within expression, see Diagnostic.Subject
return fmt.Errorf("line %d: %w", n.Line, err)
}
y.v = e.AsValue()
} else if y.v.Type() == cty.String && hasVariable(y.v.AsString()) { // "simple" variable
e, err := SimpleVarToExpression(y.v.AsString())
if err != nil {
return err
// TODO: point to exact location within expression, see Diagnostic.Subject
return fmt.Errorf("line %d: %w", n.Line, err)
}
y.v = e.AsValue()
}
Expand Down