{"record":{"id":"3b79b5f879c5dfe8","repo":"jesseduffield/lazydocker","slug":"can-t-convert-v-to-float64","errorCode":null,"errorMessage":"Can't convert %v to float64","messagePattern":"Can't convert (.+?) to float64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gui/presentation/container_stats.go","lineNumber":143,"sourceCode":"\t\treturn float64(i), nil\n\tcase uint32:\n\t\treturn float64(i), nil\n\tcase uint:\n\t\treturn float64(i), nil\n\tcase string:\n\t\treturn strconv.ParseFloat(i, 64)\n\tdefault:\n\t\tv := reflect.ValueOf(unk)\n\t\tv = reflect.Indirect(v)\n\t\tif v.Type().ConvertibleTo(floatType) {\n\t\t\tfv := v.Convert(floatType)\n\t\t\treturn fv.Float(), nil\n\t\t} else if v.Type().ConvertibleTo(stringType) {\n\t\t\tsv := v.Convert(stringType)\n\t\t\ts := sv.String()\n\t\t\treturn strconv.ParseFloat(s, 64)\n\t\t} else {\n\t\t\treturn math.NaN(), fmt.Errorf(\"Can't convert %v to float64\", v.Type())\n\t\t}\n\t}\n}\n","sourceCodeStart":125,"sourceCodeEnd":147,"githubUrl":"https://github.com/jesseduffield/lazydocker/blob/7e7aadc2071d58031bf2daafca1fbd4093efc23f/pkg/gui/presentation/container_stats.go#L125-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nf, err := utils.ToFloat64(stats.CPUStats.CPUUsage)  // struct sneaks in -> error\n\n// after\nf, err := utils.ToFloat64(stats.CPUStats.CPUUsage.TotalUsage) // pass the scalar field","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func toFloat64Safe(unk interface{}) (float64, error) {\n    v := reflect.Indirect(reflect.ValueOf(unk))\n    switch v.Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n         reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n         reflect.Float32, reflect.Float64:\n        return v.Convert(floatType).Float(), nil\n    case reflect.String:\n        return strconv.ParseFloat(v.String(), 64)\n    default:\n        return math.NaN(), fmt.Errorf(\"unsupported kind %s for float64\", v.Kind())\n    }\n}","tryCatchPattern":"f, err := utils.ToFloat64(rawStat)\nif err != nil || math.IsNaN(f) {\n    // skip rendering this stats field rather than crashing the stats view\n    f = 0\n}","preventionTips":["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."],"tags":["docker","reflection","type-conversion","stats","version-mismatch"],"backgroundTag":null,"analyzedSha":"7e7aadc2071d58031bf2daafca1fbd4093efc23f","analyzedAt":"2026-08-15T09:51:48.093Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}