{"record":{"id":"8423eef6ac8e15d2","repo":"mikefarah/yq","slug":"v-could-not-parse-v-as-an-int-w","errorCode":null,"errorMessage":"%v: could not parse %v as an int: %w","messagePattern":"(.+?): could not parse (.+?) as an int: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_path.go","lineNumber":31,"sourceCode":"\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\n\t}\n\treturn path, nil\n}\n\n// SETPATH(pathArray; value)\nfunc setPathOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {\n\tlog.Debugf(\"SetPath\")\n\n\tif expressionNode.RHS.Operation.OperationType != blockOpType {\n\t\treturn Context{}, fmt.Errorf(\"SETPATH must be given a block (;), got %v instead\", expressionNode.RHS.Operation.OperationType.Type)\n\t}\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_path.go#L13-L49","documentation":"Path arrays may only contain string keys or integer indices. When an element has tag !!int, yq re-parses its value with parseInt; if the underlying string cannot be parsed as an int (contradictory tag/value), the error wraps the parse failure, prefixed by the operator name (SETPATH/DELPATHS).","triggerScenarios":"Rare in practice: a node tagged !!int whose Value is not numeric — typically created via custom scripts, constructor-style input, or manual CandidateNode construction in Go embedding, e.g. a node {tag: !!int, value: \"3x\"} passed as a path element.","commonSituations":"Programmatic use of the yqlib package where nodes are built by hand or transformed with tag-assignment operators without updating values; corrupted or hand-edited intermediate YAML/JSON with wrong explicit tags.","solutions":["Fix the source node so a !!int tag carries a valid integer value","Use a !!str path element instead if the key is not an index","In Go code, validate before constructing: strconv.Atoi(value) before setting Tag = \"!!int\""],"exampleFix":"// Go, before\nn := &yqlib.CandidateNode{Kind: yqlib.ScalarNode, Tag: \"!!int\", Value: \"3x\"}\n// after\nif _, err := strconv.Atoi(\"3x\"); err != nil { /* use Tag: \"!!str\" or fix value */ }\nn := &yqlib.CandidateNode{Kind: yqlib.ScalarNode, Tag: \"!!str\", Value: \"3x\"}","handlingStrategy":"type-guard","validationCode":"// Go: before passing a node as an int path element\nif n.Tag == \"!!int\" { if _, err := strconv.Atoi(n.Value); err != nil { /* fix tag/value */ } }","typeGuard":"func isIntPathElement(n *yqlib.CandidateNode) bool {\n  if n.Tag != \"!!int\" { return false }\n  _, err := strconv.Atoi(n.Value)\n  return err == nil\n}","tryCatchPattern":null,"preventionTips":["Never assign '!!int' tags without validating the value parses as an int","Prefer !!str keys unless the path element is a genuine array index"],"tags":["yq","setpath","delpaths","path-expression","parsing"],"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"}