{"record":{"id":"9908b69ada02c704","repo":"go-delve/delve","slug":"argument-of-deferred-must-be-a-number-greater-than","errorCode":null,"errorMessage":"argument of deferred must be a number greater than 0 (use 'stack -defer' to see the list of deferred calls)","messagePattern":"argument of deferred must be a number greater than 0 \\(use 'stack -defer' to see the list of deferred calls\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":1077,"sourceCode":"\tprintfile(t, th.File, th.Line, true)\n\treturn nil\n}\n\nfunc (c *Commands) deferredCommand(t *Term, ctx callContext, argstr string) error {\n\tctx.Prefix = deferredPrefix\n\n\tspace := strings.IndexRune(argstr, ' ')\n\tif space < 0 {\n\t\treturn errors.New(\"not enough arguments\")\n\t}\n\n\tvar err error\n\tctx.Scope.DeferredCall, err = strconv.Atoi(argstr[:space])\n\tif err != nil {\n\t\treturn err\n\t}\n\tif ctx.Scope.DeferredCall <= 0 {\n\t\treturn errors.New(\"argument of deferred must be a number greater than 0 (use 'stack -defer' to see the list of deferred calls)\")\n\t}\n\treturn c.CallWithContext(argstr[space:], t, ctx)\n}\n\nfunc printscope(t *Term) error {\n\tstate, err := t.client.GetState()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfmt.Fprintf(t.stdout, \"Thread %s\\n\", t.formatThread(state.CurrentThread))\n\tif state.SelectedGoroutine != nil {\n\t\twriteGoroutineLong(t, t.stdout, state.SelectedGoroutine, \"\")\n\t}\n\treturn nil\n}\n\nfunc (t *Term) formatThread(th *api.Thread) string {","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L1059-L1095","documentation":"The 'deferred' command evaluates a deferred function call listed by 'stack -defer' by its 1-based index. This error is returned by deferredCommand when the numeric argument parsed from the command line is zero or negative. Deferred call indices are 1-based positions in the frame's deferred call list, so any value <= 0 is invalid.","triggerScenarios":"Running 'deferred 0' or 'deferred -1' in the delve terminal: strconv.Atoi succeeds but the value fails the `ctx.Scope.DeferredCall <= 0` check in deferredCommand (pkg/terminal/command.go:1077).","commonSituations":"Users forgetting that deferred calls are numbered starting at 1; scripting the command with a loop variable initialized to 0; copying an array-style zero-based index from other tools.","solutions":["Run 'stack -defer' and use the printed 1-based index","Use an index >= 1, e.g. 'deferred 1'"],"exampleFix":"// before\ndeferred 0\n// after\ndeferred 1","handlingStrategy":"validation","validationCode":"idx, err := strconv.Atoi(arg)\nif err != nil || idx <= 0 {\n\treturn fmt.Errorf(\"deferred index must be >= 1, got %q\", arg)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd deferred; err != nil && strings.Contains(err.Error(), \"argument of deferred must be\") { /* re-prompt with 'stack -defer' output */ }","preventionTips":["Always list deferred calls with 'stack -defer' first","Treat deferred call indices as 1-based","Validate numeric inputs are >= 1 before invoking"],"tags":["terminal","cli-usage","deferred-calls"],"backgroundTag":"invalid-argument-value","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}