mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-06 04:45:39 +00:00
Make merge anchor errors for traversing nonfatal
This commit is contained in:
parent
bfcb3fc6b7
commit
31628e7324
@ -245,6 +245,7 @@ func applyMergeAnchor(node *CandidateNode, merge *CandidateNode, mergeIndex int,
|
||||
return fmt.Errorf(
|
||||
"can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v",
|
||||
childValue.Tag)
|
||||
return nil
|
||||
}
|
||||
err := applyMergeAnchorMap(node, childValue, mergeIndex, context.ChildContext(newContent))
|
||||
if err != nil {
|
||||
|
||||
@ -305,9 +305,10 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, value *CandidateNode
|
||||
childValue = childValue.Alias
|
||||
}
|
||||
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",
|
||||
childValue.Tag)
|
||||
return nil
|
||||
}
|
||||
err := doTraverseMap(newMatches, childValue, wantedKey, prefs, splat)
|
||||
if err != nil {
|
||||
@ -316,7 +317,8 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, value *CandidateNode
|
||||
}
|
||||
return nil
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -573,20 +573,6 @@ var traversePathOperatorScenarios = []expressionScenario{
|
||||
"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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user