go-delve/delve · error

array too long for comparison

Error message

array too long for comparison

What it means

When comparing two arrays with == or !=, Delve loads all element children of both arrays. To bound memory it caps the number of loaded elements (MaxArrayValues); if either array has more elements than were loaded (loaded child count != the array's true Len), the comparison would be unsound, so Delve throws this error instead of returning a possibly wrong result.

Source

Thrown at pkg/proc/eval.go:2664

			return !yv.isNil(), nil
		}
	}

	if yv == nilVariable {
		switch op {
		case token.EQL:
			return xv.isNil(), nil
		case token.NEQ:
			return !xv.isNil(), nil
		}
	}

	switch xv.Kind {
	case reflect.Ptr:
		eql = xv.Children[0].Addr == yv.Children[0].Addr
	case reflect.Array:
		if int64(len(xv.Children)) != xv.Len || int64(len(yv.Children)) != yv.Len {
			return false, errors.New("array too long for comparison")
		}
		eql, err = equalChildren(xv, yv, true)
	case reflect.Struct:
		if len(xv.Children) != len(yv.Children) {
			return false, nil
		}
		if int64(len(xv.Children)) != xv.Len || int64(len(yv.Children)) != yv.Len {
			return false, errors.New("structure too deep for comparison")
		}
		eql, err = equalChildren(xv, yv, false)
	case reflect.Slice, reflect.Map, reflect.Func, reflect.Chan:
		return false, fmt.Errorf("can not compare %s variables", xv.Kind.String())
	case reflect.Interface:
		if xv.Children[0].RealType.String() != yv.Children[0].RealType.String() {
			eql = false
		} else {
			eql, err = compareOp(token.EQL, &xv.Children[0], &yv.Children[0])
		}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Increase the limit: 'config max-array-values <n>' in the CLI (or MaxArrayValues in LoadConfig) to at least the array length, then retry the comparison
  2. Compare element ranges manually, e.g. 'print arr[:16] == other[:16]' if sizes are within limits
  3. Compare a hash/summary computed by the program instead of the raw arrays in the debugger
  4. For API clients, raise cfg.MaxArrayValues when evaluating comparison expressions

Example fix

// before (dlv CLI)
(dlv) print a == b   // len(a)=1024 > max-array-values -> error

// after
(dlv) config max-array-values 1024
(dlv) print a == b
Defensive patterns

Strategy: validation

Validate before calling

// before comparing arrays in dlv
(dlv) print len(arrA)
(dlv) print len(arrB)
// raise the child limit if the arrays exceed it:
(dlv) config max-array-values 1024

Type guard

func comparableArrays[T any](a, b []T, maxLoaded int) bool {
    return len(a) <= maxLoaded && len(b) <= maxLoaded
}

Try / catch

// RPC client pattern
val, err := client.EvalVariable(scope, "a == b", cfg)
if err != nil && strings.Contains(err.Error(), "array too long for comparison") {
    cfg.MaxArrayValues = 1024
    val, err = client.EvalVariable(scope, "a == b", cfg)
}

Prevention

When it happens

Trigger: Evaluating 'print arrA == arrB' (or !=) where at least one array's Len exceeds the configured MaxArrayValues so its children were truncated at load time.

Common situations: Comparing large fixed-size buffers (checksums, keys, crypto blocks) in the debugger with default array-value limits; API clients using a small MaxArrayValues in LoadConfig.

Related errors


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