wavetermdev/waveterm · error
cannot convert %s: %v
Error message
cannot convert %s: %v
What it means
SetBaseConfigValue wraps a convertJsonNumber failure as 'cannot convert %s: %v' when the supplied value is a json.Number that cannot be converted to the key's declared type (int64, float64, or string). The key name and the inner conversion error are included.
Source
Thrown at pkg/wconfig/settingsconfig.go:865
if len(cerrs) > 0 {
return fmt.Errorf("error reading config file: %v", cerrs[0])
}
if m == nil {
m = make(waveobj.MetaMapType)
}
for configKey, val := range toMerge {
ctype := getConfigKeyType(configKey)
if ctype == nil {
return fmt.Errorf("invalid config key: %s", configKey)
}
if val == nil {
delete(m, configKey)
} else {
rtype := reflect.TypeOf(val)
if rtype == reflect.TypeOf(dummyNumber) {
convertedVal, err := convertJsonNumber(val.(json.Number), ctype)
if err != nil {
return fmt.Errorf("cannot convert %s: %v", configKey, err)
}
val = convertedVal
rtype = reflect.TypeOf(val)
}
if rtype != ctype {
if ctype == reflect.PointerTo(rtype) {
m[configKey] = &val
} else {
return fmt.Errorf("invalid value type for %s: %T", configKey, val)
}
}
m[configKey] = val
}
}
return WriteWaveHomeConfigFile(SettingsFile, m)
}
func SetConnectionsConfigValue(connName string, toMerge waveobj.MetaMapType) error {View on GitHub (pinned to a4447c1563)
Solutions
- Read the inner error: fix the number (make it integral, in range, or valid)
- Prefer passing native Go types (int64, float64, string, bool) instead of json.Number
- Confirm the key's declared type matches the value you are supplying
Example fix
// before
wconfig.SetBaseConfigValue(waveobj.MetaMapType{"term:fontsize": json.Number("12.75")})
// after
wconfig.SetBaseConfigValue(waveobj.MetaMapType{"term:fontsize": 13}) Defensive patterns
Strategy: validation
Validate before calling
// decode numbers into concrete types before merging
if raw, ok := val.(json.Number); ok {
if i, err := raw.Int64(); err == nil {
val = i
} else if f, err := raw.Float64(); err == nil {
val = f
}
} Try / catch
if err := wconfig.SetBaseConfigValue(m); err != nil {
if strings.Contains(err.Error(), "cannot convert") {
return fmt.Errorf("fix numeric value type before merge: %w", err)
}
return err
} Prevention
- Avoid passing json.Number into SetBaseConfigValue; convert first
- Ensure integers are whole and in range for int64 keys
- Verify each key's declared type before merging
When it happens
Trigger: Passing json.Number values via SetBaseConfigValue where the number is fractional/out-of-range for an int64 key, invalid for a float64 key, or the key's type is not number-convertible at all.
Common situations: Round-tripping parsed JSON where numbers arrive as json.Number; supplying decimals to integer settings; supplying numbers to boolean/struct settings.
Related errors
- invalid number for int64: %s
- invalid number for float64: %s
- cannot convert number to %s
- error setting telemetry value: %w
- error reading config file: %v
AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01).
Data as JSON: /api/errors/2589e098dd377a3a.
Report an issue: GitHub.