{"record":{"id":"65eff6d6abf418cb","repo":"mikefarah/yq","slug":"expected-to-find-1-number-got-v-instead","errorCode":null,"errorMessage":"expected to find 1 number, got %v instead","messagePattern":"expected to find 1 number, got (.+?) instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_slice.go","lineNumber":14,"sourceCode":"package yqlib\n\nimport (\n\t\"container/list\"\n\t\"fmt\"\n)\n\nfunc getSliceNumber(d *dataTreeNavigator, context Context, node *CandidateNode, expressionNode *ExpressionNode) (int, error) {\n\tresult, err := d.GetMatchingNodes(context.SingleChildContext(node), expressionNode)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif result.MatchingNodes.Len() != 1 {\n\t\treturn 0, fmt.Errorf(\"expected to find 1 number, got %v instead\", result.MatchingNodes.Len())\n\t}\n\treturn parseInt(result.MatchingNodes.Front().Value.(*CandidateNode).Value)\n}\n\n// clampSliceIndex resolves a possibly-negative slice index against\n// length and clamps the result to [0, length].\nfunc clampSliceIndex(index, length int) int {\n\tif index < 0 {\n\t\tindex += length\n\t}\n\tif index < 0 {\n\t\treturn 0\n\t}\n\tif index > length {\n\t\treturn length\n\t}\n\treturn index\n}","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_slice.go#L1-L32","documentation":"getSliceNumber evaluates one of the index sub-expressions of the slice operator ([start:end]) and requires it to yield exactly one node, because a slice edge must be a single integer. The expression returned %v nodes — either it emitted multiple results (e.g. .[] or a multi-match select) or none at all.","triggerScenarios":"Thrown at pkg/yqlib/operator_slice.go:14 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a single integer literal or expression for each slice bound: .[1:3]","Replace multi-match expressions with one that yields one number (e.g. (.n // 0))","Check for null matches: use defaults so the bound always resolves"],"exampleFix":null,"handlingStrategy":"validation","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"}