{"record":{"id":"b74084f4dd3343f9","repo":"go-delve/delve","slug":"wrong-number-of-arguments-to-len-d","errorCode":null,"errorMessage":"wrong number of arguments to len: %d","messagePattern":"wrong number of arguments to len: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":1927,"sourceCode":"\tcase reflect.Slice:\n\t\treturn newConstant(constant.MakeInt64(arg.Cap), arg.bi, arg.mem), nil\n\tcase reflect.Chan:\n\t\targ.loadValue(LoadFullValue())\n\t\tif arg.Unreadable != nil {\n\t\t\treturn nil, arg.Unreadable\n\t\t}\n\t\tif arg.Base == 0 {\n\t\t\treturn newConstant(constant.MakeInt64(0), arg.bi, arg.mem), nil\n\t\t}\n\t\treturn newConstant(arg.Children[1].Value, arg.bi, arg.mem), nil\n\tdefault:\n\t\treturn nil, invalidArgErr\n\t}\n}\n\nfunc lenBuiltin(args []*Variable, nodeargs []ast.Expr) (*Variable, error) {\n\tif len(args) != 1 {\n\t\treturn nil, fmt.Errorf(\"wrong number of arguments to len: %d\", len(args))\n\t}\n\targ := args[0]\n\tinvalidArgErr := fmt.Errorf(\"invalid argument %s (type %s) for len\", astutil.ExprToString(nodeargs[0]), arg.TypeString())\n\n\tswitch arg.Kind {\n\tcase reflect.Ptr:\n\t\targ = arg.maybeDereference()\n\t\tif arg.Kind != reflect.Array {\n\t\t\treturn nil, invalidArgErr\n\t\t}\n\t\tfallthrough\n\tcase reflect.Array, reflect.Slice, reflect.String:\n\t\tif arg.Unreadable != nil {\n\t\t\treturn nil, arg.Unreadable\n\t\t}\n\t\treturn newConstant(constant.MakeInt64(arg.Len), arg.bi, arg.mem), nil\n\tcase reflect.Chan:\n\t\targ.loadValue(LoadFullValue())","sourceCodeStart":1909,"sourceCodeEnd":1945,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L1909-L1945","documentation":"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.","triggerScenarios":"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).","commonSituations":"Typos like `len a b`, pasting multi-argument calls from other languages, or constructing expressions programmatically and miscounting args in the eval API.","solutions":["Pass exactly one argument: `len(<expr>)`.","If you need combined lengths, evaluate each operand separately.","If building the call programmatically, assert len(args)==1 before calling the evaluator."],"exampleFix":"// before\nlen(a, b)\n// after\nlen(a)\nlen(b)","handlingStrategy":"validation","validationCode":"args, err := parseCallArgs(expr)\nif err != nil || len(args) != 1 {\n    return fmt.Errorf(\"len takes exactly 1 argument, got %d\", len(args))\n}","typeGuard":null,"tryCatchPattern":"val, err := eval(expr)\nif err != nil && strings.Contains(err.Error(), \"wrong number of arguments to len\") {\n    // fix the call arity and retry\n}","preventionTips":["Always write len(expr) with a single parenthesized argument.","Check for stray commas or extra tokens when typing debugger expressions.","If building calls programmatically, assert len(args) == 1 first."],"tags":["debugger","go","expression-evaluation","arity"],"backgroundTag":"wrong-builtin-arg-count","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}