{"record":{"id":"8bd48c0e5013b700","repo":"mikefarah/yq","slug":"can-only-use-merge-anchors-with-maps-map-or-se","errorCode":null,"errorMessage":"can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v","messagePattern":"can only use merge anchors with maps \\(!!map\\) or sequences \\(!!seq\\) of maps, but got sequence containing (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_anchors_aliases.go","lineNumber":178,"sourceCode":"\t\t\tsequence := valueNode\n\t\t\tif sequence.Kind == AliasNode {\n\t\t\t\tsequence = sequence.Alias\n\t\t\t}\n\t\t\tif sequence.Kind != SequenceNode {\n\t\t\t\tsequence = &CandidateNode{Content: []*CandidateNode{sequence}}\n\t\t\t}\n\t\t\tfor index := 0; index < len(sequence.Content); index = index + 1 {\n\t\t\t\t// for merge anchors, we only set them if the key is not already in node or the newContent\n\t\t\t\tmergeNodeSeq := sequence.Content[index]\n\t\t\t\tif mergeNodeSeq.Kind == AliasNode {\n\t\t\t\t\tmergeNodeSeq = mergeNodeSeq.Alias\n\t\t\t\t}\n\t\t\t\tmergeNodeSeq = mergeNodeSeq.Copy()\n\t\t\t\tif err := explodeNode(mergeNodeSeq, Context{}); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tif mergeNodeSeq.Kind != MappingNode {\n\t\t\t\t\treturn fmt.Errorf(\"can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v\", mergeNodeSeq.Tag)\n\t\t\t\t}\n\t\t\t\titemsToAdd := mergeNodeSeq.FilterMapContentByKey(func(keyNode *CandidateNode) bool {\n\t\t\t\t\treturn getContentValueByKey(node.Content, keyNode.Value) == nil &&\n\t\t\t\t\t\tgetContentValueByKey(newContent, keyNode.Value) == nil\n\t\t\t\t})\n\n\t\t\t\tfor _, item := range itemsToAdd {\n\t\t\t\t\tcopied := item.Copy()\n\t\t\t\t\tcopied.Parent = node\n\t\t\t\t\tnewContent = append(newContent, copied)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tnode.Content = newContent\n\treturn nil\n}\n","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_anchors_aliases.go#L160-L196","documentation":"While exploding a merge-key ('<<') anchor whose value is a sequence, fixedReconstructAliasedMap found an element of that sequence that is not itself a map. YAML merge semantics require each merged entry to be a mapping (or a single map), so a sequence containing scalars/arrays cannot be merged into the parent map and the explode fails.","triggerScenarios":"Thrown at pkg/yqlib/operator_anchors_aliases.go:178 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Make every element of the merge sequence a mapping","Use a single map as the merge value: <<: *anchor","If the sequence of non-maps is intentional, merge it manually with e.g. *a + *b instead of '<<'"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}