go-delve/delve · error

Invalid frame %d

Error message

Invalid frame %d

What it means

The terminal's frame command switches the current stack frame (frame <n> [command]). When a negative frame number is supplied, the debugger client is never queried; the command rejects it immediately with 'Invalid frame %d'. Frames are zero-based and only non-negative indices are meaningful.

Source

Thrown at pkg/terminal/command.go:1042

		if frame, err = strconv.Atoi(args[0]); err != nil {
			return err
		}
		if len(args) > 1 {
			arg = args[1]
		}
	}
	switch direction {
	case frameUp:
		frame = c.frame + frame
	case frameDown:
		frame = c.frame - frame
	}
	if len(arg) > 0 {
		ctx.Scope.Frame = frame
		return c.CallWithContext(arg, t, ctx)
	}
	if frame < 0 {
		return fmt.Errorf("Invalid frame %d", frame)
	}
	stack, err := t.client.Stacktrace(ctx.Scope.GoroutineID, frame, frame, 0, nil)
	if err != nil {
		return err
	}
	if len(stack) == 0 {
		return fmt.Errorf("Invalid frame %d", frame)
	}
	c.frame = frame
	state, err := t.client.GetState()
	if err != nil {
		return err
	}
	printcontext(t, state)
	th := stack[0]
	fmt.Fprintf(t.stdout, "Frame %d: %s:%d (PC: %x)\n", frame, t.formatPath(th.File), th.Line, th.PC)
	printfile(t, th.File, th.Line, true)
	return nil

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Use a non-negative frame index; frames start at 0 (the innermost/current frame).
  2. If you want a frame relative to the top of the stack, compute the absolute index from a stacktrace first.
  3. Note: `frame -1 <cmd>` with an argument skips this guard (it forwards to CallWithContext), but valid frame selection still requires index >= 0.

Example fix

# before
frame -1
# after
frame 0   # or pick a valid index from the stacktrace output
Defensive patterns

Strategy: validation

Validate before calling

if frame < 0 {
    return fmt.Errorf("frame index must be >= 0, got %d", frame)
}

Type guard

func isValidFrameIndex(n int) bool { return n >= 0 }

Try / catch

if err := cmd.Call("frame -1"); err != nil {
    if strings.HasPrefix(err.Error(), "Invalid frame") {
        // prompt user to use a non-negative index
    }
    return err
}

Prevention

When it happens

Trigger: Running `frame -1` or any negative-numbered frame command in the Delve CLI (or via the terminal command interface), without a trailing command argument (arg is empty), so the frame < 0 guard fires.

Common situations: Typing negative frame indices expecting Python-like negative indexing (counting from the innermost/top frame backwards); scripts computing frame offsets that underflow to negative values.

Related errors


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