Skip to content

Commit

Permalink
chore: Change NodeError fields to private
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jul 26, 2024
1 parent ec084b3 commit da38819
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 13 additions & 5 deletions internal/visitor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@ import (
"gopkg.in/yaml.v3"
)

func NewNodeError(err error, name string, node *yaml.Node) NodeError {
return NodeError{
err: err,
name: name,
node: node,
}
}

type NodeError struct {
Err error
Name string
Node *yaml.Node
err error
name string
node *yaml.Node
}

func (e NodeError) Error() string {
return fmt.Sprintf("%s:%d:%d: %s", e.Name, e.Node.Line, e.Node.Column, e.Err)
return fmt.Sprintf("%s:%d:%d: %s", e.name, e.node.Line, e.node.Column, e.err)
}

func (e NodeError) Unwrap() error {
return e.Err
return e.err
}
2 changes: 1 addition & 1 deletion internal/visitor/find_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (visitor *FindArgs) FindArgs(n *yaml.Node, value string) error {
Option("missingkey=zero").
Parse(tmplSrc)
if err != nil {
return NodeError{Err: err, Name: visitor.path, Node: n}
return NewNodeError(err, visitor.path, n)
}

for _, field := range listTemplFields(tmpl) {
Expand Down
6 changes: 3 additions & 3 deletions internal/visitor/template_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (t TemplateComments) Template(name string, n *yaml.Node, tmplSrc string, tm
Option("missingkey=error").
Parse(tmplSrc)
if err != nil {
return NodeError{Err: err, Name: name, Node: n}
return NewNodeError(err, name, n)
}

if t.conf.Values != nil {
Expand All @@ -111,7 +111,7 @@ func (t TemplateComments) Template(name string, n *yaml.Node, tmplSrc string, tm

var buf bytes.Buffer
if err = tmpl.Execute(&buf, t.conf.Values); err != nil {
return NodeError{Err: err, Name: name, Node: n}
return NewNodeError(err, name, n)
}

if buf.String() != n.Value {
Expand All @@ -123,7 +123,7 @@ func (t TemplateComments) Template(name string, n *yaml.Node, tmplSrc string, tm
var tmpNode yaml.Node

if err := yaml.Unmarshal(buf.Bytes(), &tmpNode); err != nil {
return NodeError{Err: err, Name: name, Node: n}
return NewNodeError(err, name, n)
}

content := tmpNode.Content[0]
Expand Down

0 comments on commit da38819

Please sign in to comment.