{"record":{"id":"88c233579aeb000d","repo":"mikefarah/yq","slug":"node-at-path-v-is-not-an-array-it-s-a-v-88c233","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_shuffle.go","lineNumber":22,"sourceCode":"\t\"container/list\"\n\t\"fmt\"\n\t\"math/rand\"\n)\n\nfunc shuffleOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {\n\n\t// ignore CWE-338 gosec issue of not using crypto/rand\n\t// this is just to shuffle an array rather generating a\n\t// secret or something that needs proper rand.\n\tmyRand := rand.New(rand.NewSource(Now().UnixNano())) // #nosec\n\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\tresult := candidate.Copy()\n\n\t\ta := result.Content\n\n\t\tmyRand.Shuffle(len(a), func(i, j int) {\n\t\t\ta[i], a[j] = a[j], a[i]\n\t\t\toldIndex := a[i].Key.Value\n\t\t\ta[i].Key.Value = a[j].Key.Value\n\t\t\ta[j].Key.Value = oldIndex\n\t\t})\n\n\t\tresults.PushBack(result)\n\t}\n\treturn context.ChildContext(results), nil\n}\n","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_shuffle.go#L4-L40","documentation":"The shuffle operator iterates matched nodes and requires each to be a SequenceNode — it applies a Fisher-Yates style reshuffle of array elements using math/rand. On the first non-array node it errors, printing the node's path and its actual tag (e.g. !!map or !!str).","triggerScenarios":"Thrown at pkg/yqlib/operator_shuffle.go:22 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Apply shuffle only to arrays: .items | shuffle","Wrap scalars: [.] | shuffle","Verify the field is a list and not null before shuffling"],"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"}