{"record":{"id":"3b2ff170745673d5","repo":"wavetermdev/waveterm","slug":"value-at-index-d-is-not-a-number","errorCode":null,"errorMessage":"value at index %d is not a number","messagePattern":"value at index (.+?) is not a number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/aiusechat/tools.go","lineNumber":310,"sourceCode":"\t\t\tvaluesInterface, ok := inputMap[\"values\"]\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"missing values parameter\")\n\t\t\t}\n\n\t\t\tvaluesSlice, ok := valuesInterface.([]any)\n\t\t\tif !ok {\n\t\t\t\treturn nil, fmt.Errorf(\"values must be an array\")\n\t\t\t}\n\n\t\t\tif len(valuesSlice) == 0 {\n\t\t\t\treturn 0, nil\n\t\t\t}\n\n\t\t\tsum := 0\n\t\t\tfor i, val := range valuesSlice {\n\t\t\t\tfloatVal, ok := val.(float64)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"value at index %d is not a number\", i)\n\t\t\t\t}\n\t\t\t\tsum += int(floatVal)\n\t\t\t}\n\n\t\t\treturn sum, nil\n\t\t},\n\t}\n}\n","sourceCodeStart":292,"sourceCodeEnd":319,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/aiusechat/tools.go#L292-L319","documentation":"During summation each element of valuesSlice is asserted to float64 (the type encoding/json produces for any JSON number). Any element that isn't a plain number (string, bool, nested array/object, null) aborts with the offending index. The float is truncated to int before accumulation.","triggerScenarios":"Tool called with a mixed array such as {\"values\": [1, \"two\", 3]}, {\"values\": [1, null, 3]}, or {\"values\": [[1],[2]]} — element at index i fails the float64 assertion.","commonSituations":"Model emitting quoted numbers (\"5\" instead of 5); strings embedded for units (\"3px\"); nulls representing missing data; nested arrays the model intended to flatten.","solutions":["Send only numeric JSON values in the array: {\"values\": [1, 2, 3]} — unquoted, no nulls","If numbers may arrive as strings, preprocess/coerce them (parseFloat / strconv) before calling, or wrap the tool with a coercing shim","Note truncation: the tool int-truncates floats; pre-round client-side if rounding behavior matters"],"exampleFix":"// before\nanySum({\"values\": [1, \"2\", 3]})\n// after\nanySum({\"values\": [1, 2, 3]})","handlingStrategy":"validation","validationCode":"for i, v := range values { if _, ok := v.(float64); !ok { return fmt.Errorf(\"element %d not a number\", i) } }","typeGuard":"func allNumbers(s []any) bool { for _, v := range s { if _, ok := v.(float64); !ok { return false } }; return true }","tryCatchPattern":"out, err := tool.Call(input); if err != nil && strings.Contains(err.Error(), \"is not a number\") { return sanitizeAndRetry(err) }","preventionTips":["Send unquoted JSON numbers only; no strings, nulls, or nested arrays","Strip units (\"3px\" -> 3) and drop nulls before calling","Remember the tool truncates floats via int() — pre-round if needed"],"tags":["tool-input","type-mismatch","array-validation"],"backgroundTag":"parameter-type-mismatch","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}