jesseduffield/lazydocker · error
Can't convert %v to float64
Error message
Can't convert %v to float64
What it means
This is the default branch of a reflective ToFloat64 helper (container_stats.go): given a value of unknown type, it tries reflect conversion to float64, then to string followed by strconv.ParseFloat. If the concrete type is convertible to neither (struct, map, slice, channel, func...), it returns NaN plus this error naming the offending reflect.Type. It fires while normalizing docker stats payload fields.
Source
Thrown at pkg/gui/presentation/container_stats.go:143
return float64(i), nil
case uint32:
return float64(i), nil
case uint:
return float64(i), nil
case string:
return strconv.ParseFloat(i, 64)
default:
v := reflect.ValueOf(unk)
v = reflect.Indirect(v)
if v.Type().ConvertibleTo(floatType) {
fv := v.Convert(floatType)
return fv.Float(), nil
} else if v.Type().ConvertibleTo(stringType) {
sv := v.Convert(stringType)
s := sv.String()
return strconv.ParseFloat(s, 64)
} else {
return math.NaN(), fmt.Errorf("Can't convert %v to float64", v.Type())
}
}
}
View on GitHub (pinned to 7e7aadc207)
Solutions
- Update lazydocker to the latest release — stats parsing is actively adjusted for new docker versions.
- Check `docker version` and `docker stats <container>` directly to see if the daemon emits unusual fields; align daemon and client versions.
- If embedding lazydocker's code, pre-normalize the value: JSON-decode stats into map[string]interface{} and pass only scalars to ToFloat64.
- Report the docker version + stats JSON (docker stats --no-stream) upstream so the parser can handle the type.
Example fix
// before f, err := utils.ToFloat64(stats.CPUStats.CPUUsage) // struct sneaks in -> error // after f, err := utils.ToFloat64(stats.CPUStats.CPUUsage.TotalUsage) // pass the scalar field
Defensive patterns
Strategy: type-guard
Type guard
func toFloat64Safe(unk interface{}) (float64, error) {
v := reflect.Indirect(reflect.ValueOf(unk))
switch v.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64:
return v.Convert(floatType).Float(), nil
case reflect.String:
return strconv.ParseFloat(v.String(), 64)
default:
return math.NaN(), fmt.Errorf("unsupported kind %s for float64", v.Kind())
}
} Try / catch
f, err := utils.ToFloat64(rawStat)
if err != nil || math.IsNaN(f) {
// skip rendering this stats field rather than crashing the stats view
f = 0
} Prevention
- Pass only scalar fields (ints/floats/strings) into reflective ToFloat64, never whole structs/maps.
- Decode docker stats through a typed struct matched to your daemon's version instead of raw interface{} values.
- Keep docker engine and lazydocker versions aligned; report unseen stat shapes upstream.
When it happens
Trigger: Docker daemon (or a stats API variant) returning a value in the stats structure whose Go type after reflect.Indirect is not convertible to float64 or string — e.g. a nested map or struct where a scalar was expected in CPU/memory stats fields.
Common situations: Docker engine versions that changed/extended the stats JSON shape; alternate API-compatible daemons (podman, rootless docker) emitting richer or differently-typed stat fields; cgroup v2 hosts exposing stats fields lazydocker's parser did not anticipate.
Related errors
- expected docker.EndpointMeta, got %T
- Cannot proceed until docker gives us more information about
- Container does not support attaching. You must either run th
- You cannot attach to a stopped container, you need to start
- container is not running
AI-assisted analysis of jesseduffield/lazydocker@7e7aadc207 (2026-08-15).
Data as JSON: /api/errors/3b79b5f879c5dfe8.
Report an issue: GitHub.