wavetermdev/waveterm · error
value at index %d is not a number
Error message
value at index %d is not a number
What it means
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.
Source
Thrown at pkg/aiusechat/tools.go:310
valuesInterface, ok := inputMap["values"]
if !ok {
return nil, fmt.Errorf("missing values parameter")
}
valuesSlice, ok := valuesInterface.([]any)
if !ok {
return nil, fmt.Errorf("values must be an array")
}
if len(valuesSlice) == 0 {
return 0, nil
}
sum := 0
for i, val := range valuesSlice {
floatVal, ok := val.(float64)
if !ok {
return nil, fmt.Errorf("value at index %d is not a number", i)
}
sum += int(floatVal)
}
return sum, nil
},
}
}
View on GitHub (pinned to a4447c1563)
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
Example fix
// before
anySum({"values": [1, "2", 3]})
// after
anySum({"values": [1, 2, 3]}) Defensive patterns
Strategy: validation
Validate before calling
for i, v := range values { if _, ok := v.(float64); !ok { return fmt.Errorf("element %d not a number", i) } } Type guard
func allNumbers(s []any) bool { for _, v := range s { if _, ok := v.(float64); !ok { return false } }; return true } Try / catch
out, err := tool.Call(input); if err != nil && strings.Contains(err.Error(), "is not a number") { return sanitizeAndRetry(err) } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Model emitting quoted numbers ("5" instead of 5); strings embedded for units ("3px"); nulls representing missing data; nested arrays the model intended to flatten.
Related errors
- values must be an array
- invalid input format
- invalid input format: %w
- Invalid path part: ${pathPart}
- convertFileUIMessagePart expects 'file' type, got '%s'
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/3b2ff170745673d5.
Report an issue: GitHub.