wavetermdev/waveterm · error

invalid number for float64: %s

Error message

invalid number for float64: %s

What it means

convertJsonNumber fails when the target config field is float64 but num.Float64() errors — the JSON number is malformed or out of float64 range. The offending number string is included in the message.

Source

Thrown at pkg/wconfig/settingsconfig.go:837

var dummyNumber json.Number

func convertJsonNumber(num json.Number, ctype reflect.Type) (interface{}, error) {
	// ctype might be int64, float64, string, *int64, *float64, *string
	// switch on ctype first
	if ctype.Kind() == reflect.Pointer {
		ctype = ctype.Elem()
	}
	if reflect.Int64 == ctype.Kind() {
		if ival, err := num.Int64(); err == nil {
			return ival, nil
		}
		return nil, fmt.Errorf("invalid number for int64: %s", num)
	}
	if reflect.Float64 == ctype.Kind() {
		if fval, err := num.Float64(); err == nil {
			return fval, nil
		}
		return nil, fmt.Errorf("invalid number for float64: %s", num)
	}
	if reflect.String == ctype.Kind() {
		return num.String(), nil
	}
	return nil, fmt.Errorf("cannot convert number to %s", ctype)
}

func SetBaseConfigValue(toMerge waveobj.MetaMapType) error {
	m, cerrs := ReadWaveHomeConfigFile(SettingsFile)
	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 {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Replace the value with a valid finite number in the config
  2. Pass a native float64 instead of json.Number when calling SetBaseConfigValue
  3. Validate the number with strconv.ParseFloat before submitting it

Example fix

// before
val := json.Number("1e400") // out of float64 range
// after
val := json.Number("1e38")
Defensive patterns

Strategy: validation

Validate before calling

f, err := strconv.ParseFloat(num.String(), 64)
if err != nil || math.IsInf(f, 0) {
    return fmt.Errorf("value %q is not a valid float64", num.String())
}

Try / catch

if err := wconfig.SetBaseConfigValue(m); err != nil {
    if strings.Contains(err.Error(), "invalid number for float64") {
        return fmt.Errorf("supply a finite float value: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: SetBaseConfigValue passing a json.Number for a config key typed float64 where the number cannot parse as float64 (extremely long digits, invalid literal that survived as json.Number).

Common situations: Programmatic config manipulation inserting malformed numeric strings; numbers exceeding IEEE-754 range like 1e400; corrupted config files with concatenated digits.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/6ecb1955e010a3bd. Report an issue: GitHub.