ory/hydra · warning

unable to cast %#v of type %T to []float64

Error message

unable to cast %#v of type %T to []float64

What it means

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.

Source

Thrown at oryx/castx/castx.go:24

import (
	"encoding/csv"
	"fmt"
	"reflect"
	"strings"

	"github.com/spf13/cast"
)

// ToFloatSlice casts an interface to a []float64 type.
func ToFloatSlice(i interface{}) []float64 {
	f, _ := ToFloatSliceE(i)
	return f
}

// ToFloatSliceE casts an interface to a []float64 type.
func ToFloatSliceE(i interface{}) ([]float64, error) {
	if i == nil {
		return []float64{}, fmt.Errorf("unable to cast %#v of type %T to []float64", i, i)
	}

	switch v := i.(type) {
	case []float64:
		return v, nil
	}

	kind := reflect.TypeOf(i).Kind()
	switch kind {
	case reflect.Slice, reflect.Array:
		s := reflect.ValueOf(i)
		a := make([]float64, s.Len())
		for j := range a {
			val, err := cast.ToFloat64E(s.Index(j).Interface())
			if err != nil {
				return []float64{}, fmt.Errorf("unable to cast %#v of type %T to []float64", i, i)
			}
			a[j] = val

View on GitHub (pinned to 4174065ffb)

Solutions

  1. Ensure the value is initialized before casting
  2. Use the non-error ToFloatSlice wrapper if an empty slice on nil is acceptable
  3. Check the source config/JSON for the missing key

Example fix

// before
v, err := castx.ToFloatSliceE(maybeNil)
// after
if maybeNil == nil { maybeNil = []interface{}{} }
v, err := castx.ToFloatSliceE(maybeNil)
Defensive patterns

Strategy: type-guard

Validate before calling

if v == nil { return []float64{}, nil }

Type guard

func nonNilSlice(v any) bool { return v != nil }

Try / catch

if v, err := castx.ToFloatSliceE(x); err != nil {
    log.Printf("cast failed, using default: %v", err)
}

Prevention

When it happens

Trigger: Calling ToFloatSliceE(nil), or feeding configuration/metadata values that are unset (nil) into a float-slice cast.

Common situations: Reading an optional config key that was never set, JSON fields absent from the payload, map values missing before casting.

Related errors


AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03). Data as JSON: /api/errors/797d43b826517be2. Report an issue: GitHub.