go-delve/delve · error

argument of deferred must be a number greater than 0 (use 's

Error message

argument of deferred must be a number greater than 0 (use 'stack -defer' to see the list of deferred calls)

What it means

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.

Source

Thrown at pkg/terminal/command.go:1077

	printfile(t, th.File, th.Line, true)
	return nil
}

func (c *Commands) deferredCommand(t *Term, ctx callContext, argstr string) error {
	ctx.Prefix = deferredPrefix

	space := strings.IndexRune(argstr, ' ')
	if space < 0 {
		return errors.New("not enough arguments")
	}

	var err error
	ctx.Scope.DeferredCall, err = strconv.Atoi(argstr[:space])
	if err != nil {
		return err
	}
	if ctx.Scope.DeferredCall <= 0 {
		return errors.New("argument of deferred must be a number greater than 0 (use 'stack -defer' to see the list of deferred calls)")
	}
	return c.CallWithContext(argstr[space:], t, ctx)
}

func printscope(t *Term) error {
	state, err := t.client.GetState()
	if err != nil {
		return err
	}

	fmt.Fprintf(t.stdout, "Thread %s\n", t.formatThread(state.CurrentThread))
	if state.SelectedGoroutine != nil {
		writeGoroutineLong(t, t.stdout, state.SelectedGoroutine, "")
	}
	return nil
}

func (t *Term) formatThread(th *api.Thread) string {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Run 'stack -defer' and use the printed 1-based index
  2. Use an index >= 1, e.g. 'deferred 1'

Example fix

// before
deferred 0
// after
deferred 1
Defensive patterns

Strategy: validation

Validate before calling

idx, err := strconv.Atoi(arg)
if err != nil || idx <= 0 {
	return fmt.Errorf("deferred index must be >= 1, got %q", arg)
}

Try / catch

if err := cmd deferred; err != nil && strings.Contains(err.Error(), "argument of deferred must be") { /* re-prompt with 'stack -defer' output */ }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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