implements to replacements value in the structured data

This commit is contained in:
koba1t
2024-02-22 04:35:54 +09:00
parent 39086340ad
commit 2dc0d0da8b
3 changed files with 87 additions and 2 deletions

View File

@@ -830,6 +830,10 @@ func (e *InvalidNodeKindError) Error() string {
return msg
}
func (e *InvalidNodeKindError) Unwrap() error {
return errors.Errorf("InvalidNodeKindError")
}
func (e *InvalidNodeKindError) ActualNodeKind() Kind {
return e.node.YNode().Kind
}

View File

@@ -137,10 +137,20 @@ func (p *PathMatcher) visitEveryElem(elem *RNode) error {
func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
// lookup the field
field, err := rn.Pipe(Get(p.Path[0]))
if err != nil || (!IsCreate(p.Create) && field == nil) {
if err != nil {
// check error is an invalid kind error
invalidKindErr := &InvalidNodeKindError{}
if errors.As(err, &invalidKindErr) {
// if the field is valid json or yaml, continue to lookup the next part of the path
fmt.Print("-----------------------------\nOUTPUT: ", err)
}
return nil, err
}
if !IsCreate(p.Create) && field == nil {
return nil, nil
}
if IsCreate(p.Create) && field == nil {
var nextPart string
if len(p.Path) > 1 {