{"record":{"id":"797d43b826517be2","repo":"ory/hydra","slug":"unable-to-cast-v-of-type-t-to-float64","errorCode":null,"errorMessage":"unable to cast %#v of type %T to []float64","messagePattern":"unable to cast %#v of type %T to \\[\\]float64","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"oryx/castx/castx.go","lineNumber":24,"sourceCode":"import (\n\t\"encoding/csv\"\n\t\"fmt\"\n\t\"reflect\"\n\t\"strings\"\n\n\t\"github.com/spf13/cast\"\n)\n\n// ToFloatSlice casts an interface to a []float64 type.\nfunc ToFloatSlice(i interface{}) []float64 {\n\tf, _ := ToFloatSliceE(i)\n\treturn f\n}\n\n// ToFloatSliceE casts an interface to a []float64 type.\nfunc ToFloatSliceE(i interface{}) ([]float64, error) {\n\tif i == nil {\n\t\treturn []float64{}, fmt.Errorf(\"unable to cast %#v of type %T to []float64\", i, i)\n\t}\n\n\tswitch v := i.(type) {\n\tcase []float64:\n\t\treturn v, nil\n\t}\n\n\tkind := reflect.TypeOf(i).Kind()\n\tswitch kind {\n\tcase reflect.Slice, reflect.Array:\n\t\ts := reflect.ValueOf(i)\n\t\ta := make([]float64, s.Len())\n\t\tfor j := range a {\n\t\t\tval, err := cast.ToFloat64E(s.Index(j).Interface())\n\t\t\tif err != nil {\n\t\t\t\treturn []float64{}, fmt.Errorf(\"unable to cast %#v of type %T to []float64\", i, i)\n\t\t\t}\n\t\t\ta[j] = val","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/castx/castx.go#L6-L42","documentation":"castx.ToFloatSliceE returns this when the input interface is nil, since nil cannot be cast to []float64. It is a typed-cast helper in oryx/castx; callers using ToFloatSlice get an empty slice and ignore the error, but direct ToFloatSliceE callers see it.","triggerScenarios":"Calling ToFloatSliceE(nil), or feeding configuration/metadata values that are unset (nil) into a float-slice cast.","commonSituations":"Reading an optional config key that was never set, JSON fields absent from the payload, map values missing before casting.","solutions":["Ensure the value is initialized before casting","Use the non-error ToFloatSlice wrapper if an empty slice on nil is acceptable","Check the source config/JSON for the missing key"],"exampleFix":"// before\nv, err := castx.ToFloatSliceE(maybeNil)\n// after\nif maybeNil == nil { maybeNil = []interface{}{} }\nv, err := castx.ToFloatSliceE(maybeNil)","handlingStrategy":"type-guard","validationCode":"if v == nil { return []float64{}, nil }","typeGuard":"func nonNilSlice(v any) bool { return v != nil }","tryCatchPattern":"if v, err := castx.ToFloatSliceE(x); err != nil {\n    log.Printf(\"cast failed, using default: %v\", err)\n}","preventionTips":["Default nil config values before casting","Log input types when casting fails"],"tags":["casting","golang","nil-value"],"backgroundTag":"type-cast-failed","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}