{"record":{"id":"d3cfc201a25186b1","repo":"mikefarah/yq","slug":"cannot-convert-node-value-v-at-path-v-of-tag","errorCode":null,"errorMessage":"cannot convert node value [%v] at path %v of tag %v to number","messagePattern":"cannot convert node value \\[(.+?)\\] at path (.+?) of tag (.+?) to number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/operator_to_number.go","lineNumber":45,"sourceCode":"\n\tvar results = list.New()\n\n\tfor el := context.MatchingNodes.Front(); el != nil; el = el.Next() {\n\t\tcandidate := el.Value.(*CandidateNode)\n\t\tif candidate.Kind != ScalarNode {\n\t\t\treturn Context{}, fmt.Errorf(\"cannot convert node at path %v of tag %v to number\", candidate.GetNicePath(), candidate.Tag)\n\t\t}\n\n\t\tif candidate.Tag == \"!!int\" || candidate.Tag == \"!!float\" {\n\t\t\t// it already is a number!\n\t\t\tresults.PushBack(candidate)\n\t\t} else {\n\t\t\ttag, converted := tryConvertToNumber(candidate.Value)\n\t\t\tif converted {\n\t\t\t\tresult := candidate.CreateReplacement(ScalarNode, tag, candidate.Value)\n\t\t\t\tresults.PushBack(result)\n\t\t\t} else {\n\t\t\t\treturn Context{}, fmt.Errorf(\"cannot convert node value [%v] at path %v of tag %v to number\", candidate.Value, candidate.GetNicePath(), candidate.Tag)\n\t\t\t}\n\n\t\t}\n\t}\n\n\treturn context.ChildContext(results), nil\n}\n","sourceCodeStart":27,"sourceCodeEnd":53,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/operator_to_number.go#L27-L53","documentation":"The to_number operator found a scalar whose string value cannot be parsed as an int64 or float64. tryConvertToNumber fails (both parseInt64 and ParseFloat error), so toNumberOperator returns this error including the offending value, its path, and its tag.","triggerScenarios":"`yq '.version | to_number'` where version is \"1.2.3\" (two dots), or to_number on values like \"abc\", \"12px\", \"\" (empty string scalars), or strings with thousands separators \"1,000\".","commonSituations":"Numeric-looking identifiers that are not valid numbers (semver strings, phone numbers, hex without 0x handling), locale-formatted numbers with commas, or whitespace/units embedded in the value.","solutions":["Clean/normalize the string before converting, e.g. remove non-numeric characters: `sub(\"[^0-9.]\"; \"\") | to_number`","For semver or composite values, extract the numeric part explicitly (e.g. `.version | sub(\"\\\\..*\"; \"\") | to_number`)","Handle commas/units: `gsub(\",\"; \"\") | to_number` or strip units with sub(\"px\"; \"\")","Guard with a select/filter so only parseable values reach to_number"],"exampleFix":"// before: \"1,000\" fails to parse\ncount | to_number\n// after: strip commas first\ncount | sub(\",\"; \"\") | to_number","handlingStrategy":"validation","validationCode":"// strip non-numeric characters before conversion\ncount | sub(\"[^0-9.eE+-]\"; \"\"; \"g\") | to_number","typeGuard":"// guard parseable values before converting\ndef isNumeric: test(\"^-?[0-9]+(\\\\.[0-9]+)?([eE][+-]?[0-9]+)?$\");\n.<field> | select(isNumeric) | to_number","tryCatchPattern":null,"preventionTips":["Normalize locale formats (remove commas, units, whitespace) before to_number","Treat semver/identifier strings separately — extract numeric components explicitly","Pre-validate with test() regex filters so only parseable scalars reach to_number"],"tags":["yq","to-number","type-conversion","validation","yaml"],"backgroundTag":"type-conversion-failed","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"}