go-delve/delve · error

wrong number of arguments to len: %d

Error message

wrong number of arguments to len: %d

What it means

The `len()` builtin in Delve's evaluator requires exactly one argument. This error is returned before any type checking when the argument count differs, mirroring Go's own compile-time arity rule for len.

Source

Thrown at pkg/proc/eval.go:1927

	case reflect.Slice:
		return newConstant(constant.MakeInt64(arg.Cap), arg.bi, arg.mem), nil
	case reflect.Chan:
		arg.loadValue(LoadFullValue())
		if arg.Unreadable != nil {
			return nil, arg.Unreadable
		}
		if arg.Base == 0 {
			return newConstant(constant.MakeInt64(0), arg.bi, arg.mem), nil
		}
		return newConstant(arg.Children[1].Value, arg.bi, arg.mem), nil
	default:
		return nil, invalidArgErr
	}
}

func lenBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {
	if len(args) != 1 {
		return nil, fmt.Errorf("wrong number of arguments to len: %d", len(args))
	}
	arg := args[0]
	invalidArgErr := fmt.Errorf("invalid argument %s (type %s) for len", astutil.ExprToString(nodeargs[0]), arg.TypeString())

	switch arg.Kind {
	case reflect.Ptr:
		arg = arg.maybeDereference()
		if arg.Kind != reflect.Array {
			return nil, invalidArgErr
		}
		fallthrough
	case reflect.Array, reflect.Slice, reflect.String:
		if arg.Unreadable != nil {
			return nil, arg.Unreadable
		}
		return newConstant(constant.MakeInt64(arg.Len), arg.bi, arg.mem), nil
	case reflect.Chan:
		arg.loadValue(LoadFullValue())

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Pass exactly one argument: `len(<expr>)`.
  2. If you need combined lengths, evaluate each operand separately.
  3. If building the call programmatically, assert len(args)==1 before calling the evaluator.

Example fix

// before
len(a, b)
// after
len(a)
len(b)
Defensive patterns

Strategy: validation

Validate before calling

args, err := parseCallArgs(expr)
if err != nil || len(args) != 1 {
    return fmt.Errorf("len takes exactly 1 argument, got %d", len(args))
}

Try / catch

val, err := eval(expr)
if err != nil && strings.Contains(err.Error(), "wrong number of arguments to len") {
    // fix the call arity and retry
}

Prevention

When it happens

Trigger: Evaluating `len()` with zero arguments or `len(a, b)` with two or more arguments in the debugger command line / eval API (eval.go:1927, lenBuiltin).

Common situations: Typos like `len a b`, pasting multi-argument calls from other languages, or constructing expressions programmatically and miscounting args in the eval API.

Related errors


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