go-delve/delve · error

you must specify a thread

Error message

you must specify a thread

What it means

The 'thread' command requires a numeric thread ID argument; this error is returned when it is invoked with no argument. Delve cannot switch threads without knowing which one to target.

Solutions

  1. Run 'threads' first to list available thread IDs
  2. Use 'thread <id>' with a numeric ID, e.g. 'thread 3'
  3. Use 'goroutine <n>' if you actually meant to switch goroutines

Example fix

// before
(dlv) thread
// after
(dlv) threads
(dlv) thread 5
Defensive patterns

Strategy: validation

Validate before calling

// Ensure a numeric thread id is provided
parts := strings.Fields(args)
if len(parts) != 1 {
    return errors.New("usage: thread <tid>")
}
if _, err := strconv.Atoi(parts[0]); err != nil {
    return fmt.Errorf("thread id must be an integer: %v", err)
}

Try / catch

err := term.ExecuteCommand("thread " + args)
if err != nil && strings.Contains(err.Error(), "you must specify a thread") {
    // list threads and prompt for an id
st, _ := client.ListThreads()
    printThreadChoices(st)
}

Prevention

When it happens

Trigger: Typing 'thread' alone at the (dlv) prompt instead of 'thread <tid>'.

Common situations: Habit from other debuggers where 'thread' lists or selects interactively; forgetting the ID after checking 'threads'.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at pkg/terminal/command.go:849

		}
		prefix := "  "
		if state.CurrentThread != nil && state.CurrentThread.ID == th.ID {
			prefix = "* "
		}
		if th.Function != nil {
			fmt.Fprintf(t.stdout, "%sThread %d at %#v %s:%d %s\n",
				prefix, th.ID, th.PC, t.formatPath(th.File),
				th.Line, th.Function.Name())
		} else {
			fmt.Fprintf(t.stdout, "%sThread %s\n", prefix, t.formatThread(th))
		}
	}
	return nil
}

func thread(t *Term, ctx callContext, args string) error {
	if len(args) == 0 {
		return errors.New("you must specify a thread")
	}
	tid, err := strconv.Atoi(args)
	if err != nil {
		return err
	}
	oldState, err := t.client.GetState()
	if err != nil {
		return err
	}
	newState, err := t.client.SwitchThread(tid)
	if err != nil {
		return err
	}

	oldThread := "<none>"
	newThread := "<none>"
	if oldState.CurrentThread != nil {
		oldThread = strconv.Itoa(oldState.CurrentThread.ID)

View on GitHub (pinned to a23773e6c3)