{"record":{"id":"50f65d4fdd2221d4","repo":"mikefarah/yq","slug":"node-at-path-v-is-not-an-array-it-s-a-v","errorCode":null,"errorMessage":"node at path [%v] is not an array (it's a %v)","messagePattern":"node at path \\[(.+?)\\] is not an array \\(it's a (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_reverse.go","lineNumber":15,"sourceCode":"package yqlib\n\nimport (\n\t\"container/list\"\n\t\"fmt\"\n)\n\nfunc reverseOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {\n\tresults := list.New()\n\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)\n\n\t\tif candidate.Kind != SequenceNode {\n\t\t\treturn context, fmt.Errorf(\"node at path [%v] is not an array (it's a %v)\", candidate.GetNicePath(), candidate.Tag)\n\t\t}\n\n\t\treverseList := candidate.CreateReplacementWithComments(SequenceNode, \"!!seq\", candidate.Style)\n\t\treverseContent := make([]*CandidateNode, len(candidate.Content))\n\n\t\tfor i, originalNode := range candidate.Content {\n\t\t\treverseContent[len(candidate.Content)-i-1] = originalNode\n\t\t}\n\t\treverseList.AddChildren(reverseContent)\n\t\tresults.PushBack(reverseList)\n\n\t}\n\n\treturn context.ChildContext(results), nil\n\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_reverse.go#L1-L32","documentation":"The `reverse` operator only works on arrays (sequence nodes). When a matched candidate is not a SequenceNode, yq returns this error naming the node's path and tag, so you know exactly which node failed. Note it returns the original context alongside the error, so no partial results are produced for that expression run.","triggerScenarios":"`yq 'reverse'` on a document whose root is a map or scalar; `reverse` applied to a map-valued key like `.myMap | reverse`; multi-document input where one document is not an array.","commonSituations":"Reversing a map by mistake (expecting key order reversal — use `keys | reverse` or `to_entries` instead); schema changes turning an array into an object; selecting the parent container instead of the array field.","solutions":["Select the array first: `.items | reverse` instead of `reverse` on the whole map.","If reversing map keys, use `keys | reverse` and then re-map, e.g. `to_entries | reverse | from_entries`.","Guard with `select(tag == \"!!seq\") | reverse` to only reverse arrays.","Use the path in the error to locate and fix the offending node or expression."],"exampleFix":"// before\nyq 'reverse' file.yml            # root is a map\n// after\nyq '.items | reverse' file.yml","handlingStrategy":"type-guard","validationCode":"yq -e 'tag == \"!!seq\"' <<< \"$node\" || echo \"reverse requires an array\"","typeGuard":"isSeq() { [ \"$(yq 'tag == \"!!seq\"' <<< \"$1\")\" = \"true\" ]; }","tryCatchPattern":"out=$(yq 'select(tag == \"!!seq\") | reverse' file.yml 2>&1) || { echo \"$out\"; echo \"use to_entries | reverse | from_entries for maps\"; }","preventionTips":["Select the array before reversing: .items | reverse.","Reverse map key order with keys | reverse or to_entries | reverse | from_entries.","Guard multi-doc pipelines with select(tag == \"!!seq\").","Use the path in the error message to locate the non-array node."],"tags":["yq","reverse","type-mismatch","node-kind"],"backgroundTag":"reverse-non-sequence-node","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"}