{"record":{"id":"c4185527afc34c29","repo":"mikefarah/yq","slug":"v-expected-path-array-but-got-v-instead","errorCode":null,"errorMessage":"%v: expected path array, but got %v instead","messagePattern":"(.+?): expected path array, but got (.+?) instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_path.go","lineNumber":19,"sourceCode":"package yqlib\n\nimport (\n\t\"container/list\"\n\t\"fmt\"\n)\n\nfunc createPathNodeFor(pathElement interface{}) *CandidateNode {\n\tswitch pathElement := pathElement.(type) {\n\tcase string:\n\t\treturn &CandidateNode{Kind: ScalarNode, Value: pathElement, Tag: \"!!str\"}\n\tdefault:\n\t\treturn &CandidateNode{Kind: ScalarNode, Value: fmt.Sprintf(\"%v\", pathElement), Tag: \"!!int\"}\n\t}\n}\n\nfunc getPathArrayFromNode(funcName string, node *CandidateNode) ([]interface{}, error) {\n\tif node.Kind != SequenceNode {\n\t\treturn nil, fmt.Errorf(\"%v: expected path array, but got %v instead\", funcName, node.Tag)\n\t}\n\n\tpath := make([]interface{}, len(node.Content))\n\n\tfor i, childNode := range node.Content {\n\t\tswitch childNode.Tag {\n\t\tcase \"!!str\":\n\t\t\tpath[i] = childNode.Value\n\t\tcase \"!!int\":\n\t\t\tnumber, err := parseInt(childNode.Value)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"%v: could not parse %v as an int: %w\", funcName, childNode.Value, err)\n\t\t\t}\n\t\t\tpath[i] = number\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"%v: expected either a !!str or !!int in the path, found %v instead\", funcName, childNode.Tag)\n\t\t}\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_path.go#L1-L37","documentation":"SETPATH and DELPATHS expect their path expression to evaluate to a sequence (array), whose elements are path keys/indices. getPathArrayFromNode checks node.Kind == SequenceNode and throws this error (prefixed with SETPATH or DELPATHS) when the expression instead produced a scalar, map, or null — the %v is the node's YAML tag (e.g. !!str, !!map, !!null).","triggerScenarios":"SETPATH with a non-array first argument: 'SETPATH(\"a\"; \"v\")' or 'SETPATH(.someMap; 3)', or DELPATHS('a, b') passing a scalar instead of an array of path arrays. Also when the path expression matches nothing and returns null ('!!null').","commonSituations":"Hand-written paths missing the surrounding [] brackets, refactored scripts where the path expression was changed to a scalar, expressions returning null because the document shape differs from expectations.","solutions":["Wrap path elements in an array: 'SETPATH([\"a\", \"b\"]; value)'","Check what the path expression returns ('yq '<expr> | tag'') and fix it to yield a !!seq","If the path may be missing, guard with select/alternative so a valid array is always produced"],"exampleFix":"// before\nyq 'SETPATH(\"a\"; 3)' f.yml\n// after\nyq 'SETPATH([\"a\"]; 3)' f.yml","handlingStrategy":"validation","validationCode":"yq '<pathExpr> | tag' f.yml  # must print !!seq\ntype guard: yq 'select((<pathExpr> | tag) == \"!!seq\") | SETPATH(<pathExpr>; v)' f.yml","typeGuard":"yq 'select((.p | tag) == \"!!seq\") | SETPATH(.p; 3)' f.yml","tryCatchPattern":"// shell\nout=$(yq 'SETPATH(.p; 3)' f.yml 2>&1) || { echo \"SETPATH failed: $out\"; exit 1; }","preventionTips":["Always wrap path elements in [] when calling SETPATH/DELPATHS","Check expression output tags with '| tag'","Handle missing data so paths never evaluate to null"],"tags":["yq","setpath","delpaths","path-expression","type-mismatch"],"backgroundTag":"invalid-path-expression","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"}