go-delve/delve · error
could not find target %d
Error message
could not find target %d
What it means
`target switch <pid>` looks up the given PID among the debugged targets and switches to its current thread. If no target with that PID is being debugged, the command reports this error instead of switching.
Source
Thrown at pkg/terminal/command.go:3596
return nil
case "switch":
tgts, err := t.client.ListTargets()
if err != nil {
return err
}
pid, err := strconv.Atoi(argv[1])
if err != nil {
return err
}
found := false
for _, tgt := range tgts {
if tgt.Pid == pid {
found = true
t.client.SwitchThread(tgt.CurrentThread.ID)
}
}
if !found {
return fmt.Errorf("could not find target %d", pid)
}
return nil
case "":
return errors.New("not enough arguments for 'target'")
default:
return fmt.Errorf("unknown command 'target %s'", argv[0])
}
}
func formatBreakpointName(bp *api.Breakpoint, upcase bool) string {
thing := "breakpoint"
if bp.Tracepoint {
thing = "tracepoint"
}
if bp.WatchExpr != "" {
thing = "watchpoint"
}
if upcase {View on GitHub (pinned to a23773e6c3)
Solutions
- Run `targets` to list valid target PIDs and pick one from that list
- Enable `target follow-exec -on` if you need to debug child processes
- Re-check the PID (decimal, no hex) of the process you want
- If the target exited, it can no longer be switched to
Example fix
// before target switch 9999 // after targets target switch 4242
Defensive patterns
Strategy: try-catch
Try / catch
if !pidIsTarget(targets, pid) {
return fmt.Errorf("pid %d not in target list; run 'targets'", pid)
} Prevention
- Always resolve PIDs from ListTargets output, not external process lists
When it happens
Trigger: Running `target switch 1234` where 1234 is not a PID of any process in the current TargetGroup (wrong PID, process already exited, or child process not yet spawned).
Common situations: Switching to a child process before follow-exec has spawned it; using the OS pid of a process unrelated to this debug session; a target exited and its PID is stale.
Related errors
- command not available
- you must specify a thread
- too many arguments to goroutine
- not enough arguments
- Invalid frame %d
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/275f4c45dab66d87.
Report an issue: GitHub.