{"record":{"id":"ecd943d8483899c0","repo":"mikefarah/yq","slug":"node-at-path-v-is-not-an-array-or-map-it-s-a","errorCode":null,"errorMessage":"node at path [%v] is not an array or map (it's a %v)","messagePattern":"node at path \\[(.+?)\\] is not an array or map \\(it's a (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_sort.go","lineNumber":44,"sourceCode":"\n\t\tvar sortableArray sortableNodeArray\n\n\t\tif candidate.CanVisitValues() {\n\t\t\tsortableArray = make(sortableNodeArray, 0)\n\t\t\tvisitor := func(valueNode *CandidateNode) error {\n\t\t\t\tcompareContext, err := d.GetMatchingNodes(context.SingleReadonlyChildContext(valueNode), expressionNode.RHS)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tsortableNode := sortableNode{Node: valueNode, CompareContext: compareContext, dateTimeLayout: context.GetDateTimeLayout()}\n\t\t\t\tsortableArray = append(sortableArray, sortableNode)\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tif err := candidate.VisitValues(visitor); err != nil {\n\t\t\t\treturn context, err\n\t\t\t}\n\t\t} else {\n\t\t\treturn context, fmt.Errorf(\"node at path [%v] is not an array or map (it's a %v)\", candidate.GetNicePath(), candidate.Tag)\n\t\t}\n\n\t\tsort.Stable(sortableArray)\n\n\t\tsortedList := candidate.CopyWithoutContent()\n\t\tswitch candidate.Kind {\n\t\tcase MappingNode:\n\t\t\tfor _, sortedNode := range sortableArray {\n\t\t\t\tsortedList.AddKeyValueChild(sortedNode.Node.Key, sortedNode.Node)\n\t\t\t}\n\t\tcase SequenceNode:\n\t\t\tfor _, sortedNode := range sortableArray {\n\t\t\t\tsortedList.AddChild(sortedNode.Node)\n\t\t\t}\n\t\t}\n\n\t\t// convert array of value nodes back to map\n\t\tresults.PushBack(sortedList)","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_sort.go#L26-L62","documentation":"The sort/sort_by operators require each matched node to be an array or map so there are values to order — after visiting values (or when the node cannot be visited) the kind check fails and the node's path and actual tag are reported. Sorting a scalar or null is undefined, hence the guard.","triggerScenarios":"Thrown at pkg/yqlib/operator_sort.go:44 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Apply sort only to arrays/maps: .items | sort_by(.x)","Wrap scalars: [.] | sort","Filter to collection nodes first: select(type == \"!!seq\" or type == \"!!map\")"],"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"}