{"record":{"id":"275f4c45dab66d87","repo":"go-delve/delve","slug":"could-not-find-target-d","errorCode":null,"errorMessage":"could not find target %d","messagePattern":"could not find target (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":3596,"sourceCode":"\t\treturn nil\n\tcase \"switch\":\n\t\ttgts, err := t.client.ListTargets()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tpid, err := strconv.Atoi(argv[1])\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfound := false\n\t\tfor _, tgt := range tgts {\n\t\t\tif tgt.Pid == pid {\n\t\t\t\tfound = true\n\t\t\t\tt.client.SwitchThread(tgt.CurrentThread.ID)\n\t\t\t}\n\t\t}\n\t\tif !found {\n\t\t\treturn fmt.Errorf(\"could not find target %d\", pid)\n\t\t}\n\t\treturn nil\n\tcase \"\":\n\t\treturn errors.New(\"not enough arguments for 'target'\")\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown command 'target %s'\", argv[0])\n\t}\n}\n\nfunc formatBreakpointName(bp *api.Breakpoint, upcase bool) string {\n\tthing := \"breakpoint\"\n\tif bp.Tracepoint {\n\t\tthing = \"tracepoint\"\n\t}\n\tif bp.WatchExpr != \"\" {\n\t\tthing = \"watchpoint\"\n\t}\n\tif upcase {","sourceCodeStart":3578,"sourceCodeEnd":3614,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L3578-L3614","documentation":"`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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\ntarget switch 9999\n// after\ntargets\ntarget switch 4242","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if !pidIsTarget(targets, pid) {\n    return fmt.Errorf(\"pid %d not in target list; run 'targets'\", pid)\n}","preventionTips":["Always resolve PIDs from ListTargets output, not external process lists"],"tags":["terminal","multitarget","cli"],"backgroundTag":"target-not-found","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}