Make merge anchor errors for traversing nonfatal

This commit is contained in:
Steven WdV 2025-06-16 12:23:35 +02:00
parent bfcb3fc6b7
commit 31628e7324
No known key found for this signature in database
3 changed files with 5 additions and 16 deletions

View File

@ -245,6 +245,7 @@ func applyMergeAnchor(node *CandidateNode, merge *CandidateNode, mergeIndex int,
return fmt.Errorf( return fmt.Errorf(
"can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v", "can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v",
childValue.Tag) childValue.Tag)
return nil
} }
err := applyMergeAnchorMap(node, childValue, mergeIndex, context.ChildContext(newContent)) err := applyMergeAnchorMap(node, childValue, mergeIndex, context.ChildContext(newContent))
if err != nil { if err != nil {

View File

@ -305,9 +305,10 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, value *CandidateNode
childValue = childValue.Alias childValue = childValue.Alias
} }
if childValue.Kind != MappingNode { if childValue.Kind != MappingNode {
return fmt.Errorf( log.Debugf(
"can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v", "can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v",
childValue.Tag) childValue.Tag)
return nil
} }
err := doTraverseMap(newMatches, childValue, wantedKey, prefs, splat) err := doTraverseMap(newMatches, childValue, wantedKey, prefs, splat)
if err != nil { if err != nil {
@ -316,7 +317,8 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, value *CandidateNode
} }
return nil return nil
default: default:
return fmt.Errorf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got %v", value.Tag) log.Debugf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got %v", merge.Tag)
return nil
} }
} }

View File

@ -573,20 +573,6 @@ var traversePathOperatorScenarios = []expressionScenario{
"D0, P[a 2], (!!str)::c\n", "D0, P[a 2], (!!str)::c\n",
}, },
}, },
{
skipDoc: true,
document: badAliasSample,
expression: ".steps[]",
expectedError: "can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing !!str",
skipForGoccy: true, // throws an error on parsing, that's fine
},
{
skipDoc: true,
document: `{<<: 42}`,
expression: ".[]",
expectedError: "can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got !!int",
skipForGoccy: true,
},
} }
func TestTraversePathOperatorScenarios(t *testing.T) { func TestTraversePathOperatorScenarios(t *testing.T) {