go-delve/delve · error

structure too deep for comparison

Error message

structure too deep for comparison

What it means

When comparing two structs, Delve loads all field children of both. If a struct has more fields than the configured limit (MaxStructFields / array-value caps) some fields were not loaded; comparing would silently skip fields, so Delve throws this error. The name is slightly misleading: it is about struct field truncation, not pointer depth.

Source

Thrown at pkg/proc/eval.go:2672

		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])
		}
	default:
		return false, fmt.Errorf("unimplemented comparison of %s variables", xv.Kind.String())
	}

	if op == token.NEQ {
		return !eql, err
	}
	return eql, err

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Raise the load limits (config max-array-values / max-struct-fields style config in the CLI, or MaxStructFields in LoadConfig) and retry
  2. Compare field-by-field: 'print a.Field1 == b.Field1' etc., which is often more informative anyway
  3. Compare only the fields you care about instead of whole-struct equality
  4. For API clients, increase cfg.MaxStructFields before evaluating the comparison

Example fix

// before (dlv CLI)
(dlv) print cfgA == cfgB   // struct with many fields -> error

// after
(dlv) print cfgA.Name == cfgB.Name && cfgA.Port == cfgB.Port
Defensive patterns

Strategy: validation

Validate before calling

// before comparing structs in dlv, prefer field-wise comparison for large structs:
(dlv) print a.Field1 == b.Field1 && a.Field2 == b.Field2

Try / catch

// RPC client pattern
val, err := client.EvalVariable(scope, "sa == sb", cfg)
if err != nil && strings.Contains(err.Error(), "structure too deep for comparison") {
    // fall back to per-field evaluation
    for _, f := range fields {
        client.EvalVariable(scope, fmt.Sprintf("sa.%s == sb.%s", f, f), cfg)
    }
}

Prevention

When it happens

Trigger: Evaluating 'print structA == structB' (or !=) where at least one struct has more fields than were loaded (len(Children) != v.Len) due to load limits.

Common situations: Comparing large configuration/log structs in the debugger; API clients with restrictive LoadConfig limits evaluating struct equality expressions.

Related errors


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