go-delve/delve · error

variable to reslice is not an array, slice, or map

Error message

variable to reslice is not an array, slice, or map

What it means

LoadResliced re-reads a container starting at a given index (used for paging through large arrays/slices/maps in the UI). It only supports array, slice, and map kinds; any other kind reaching the switch's default branch throws this error. Strings, structs, pointers, and interfaces cannot be resliced this way.

Source

Thrown at pkg/proc/eval.go:2946

// up to cfg.MaxArrayValues children.
func (v *Variable) LoadResliced(start int, cfg LoadConfig) (newV *Variable, err error) {
	switch v.Kind {
	case reflect.Array, reflect.Slice:
		low, high := int64(start), int64(start+cfg.MaxArrayValues)
		if high > v.Len {
			high = v.Len
		}
		newV, err = v.reslice(low, high, false)
		if err != nil {
			return nil, err
		}
	case reflect.Map:
		newV = v.clone()
		newV.Children = nil
		newV.loaded = false
		newV.mapSkip = start
	default:
		return nil, errors.New("variable to reslice is not an array, slice, or map")
	}
	newV.loadValue(cfg)
	return newV, nil
}

func (v *Variable) reslice(low int64, high int64, trustLen bool) (*Variable, error) {
	wrong := false
	cptrNeedsFakeSlice := false
	if v.Flags&VariableCPtr == 0 {
		if v.Kind == reflect.Slice {
			wrong = low < 0 || low > v.Cap || high < 0 || high > v.Cap
		} else {
			wrong = low < 0 || low > v.Len || high < 0 || high > v.Len
		}
	} else {
		wrong = low < 0 || high < 0
		if high == 0 {
			high = low

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Check v.Kind before calling LoadResliced and only call it for reflect.Array, reflect.Slice, or reflect.Map
  2. For strings use string indexing/slicing (reslice) semantics instead of LoadResliced
  3. Dereference pointers first (load the pointee) before attempting container paging
  4. If the kind is unexpected, reload the variable with a proper LoadConfig so Kind is populated correctly

Example fix

// before
newV, err := v.LoadResliced(start, cfg) // v.Kind == reflect.String -> error

// after
switch v.Kind {
case reflect.Array, reflect.Slice, reflect.Map:
    newV, err = v.LoadResliced(start, cfg)
default:
    err = fmt.Errorf("cannot reslice kind %s", v.Kind)
}
Defensive patterns

Strategy: type-guard

Validate before calling

// before calling LoadResliced
if v.Kind != reflect.Array && v.Kind != reflect.Slice && v.Kind != reflect.Map {
    return fmt.Errorf("cannot reslice kind %s", v.Kind)
}
newV, err := v.LoadResliced(start, cfg)

Type guard

func resliceable(v *proc.Variable) bool {
    return v != nil && (v.Kind == reflect.Array || v.Kind == reflect.Slice || v.Kind == reflect.Map)
}

Try / catch

// caller pattern
newV, err := v.LoadResliced(start, cfg)
if err != nil && strings.Contains(err.Error(), "not an array, slice, or map") {
    // fall back to loading the variable whole or re-reading its pointee
    v.LoadValue(cfg)
}

Prevention

When it happens

Trigger: Calling LoadResliced (directly or via UI/RPC paging of a large variable) on a Variable whose Kind is not Array, Slice, or Map — e.g. a string, a nil/unknown kind, a struct, or a pointer.

Common situations: A frontend or custom client paging a variable tree and calling reslice-style APIs on the wrong node type; code assuming a variable is a slice when it is actually a string or pointer; reflection-driven tooling misclassifying kinds.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/4e5260b2d82e94eb. Report an issue: GitHub.