go-delve/delve · error

unknown target command

Error message

unknown target command

What it means

The 'target' DAP command supports only the subcommands 'list', 'follow-exec', and 'switch'. Anything else in argv[0] falls into the default case and returns this generic error. It indicates the subcommand name itself (not its arguments) is unrecognized.

Source

Thrown at service/dap/command.go:326

		defer unlock()
		pid, err := strconv.Atoi(argv[1])
		if err != nil {
			return "", err
		}
		found := false
		for _, tgt := range tgrp.Targets() {
			if _, err = tgt.Valid(); err == nil && tgt.Pid() == pid {
				found = true
				tgrp.Selected = tgt
				tgt.SwitchThread(pid)
			}
		}
		if !found {
			return "", fmt.Errorf("could not find target %d", pid)
		}
		return fmt.Sprintf("Switched to process %d", pid), err
	default:
		return "", fmt.Errorf("unknown target command")
	}
}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Use one of: 'target list', 'target follow-exec [-on regex|-off]', 'target switch <pid>'.
  2. Replace GDB-style 'target select <pid>' with 'target switch <pid>'.
  3. Perform actions like detach through the dedicated DAP requests (disconnect/restart) rather than the target command.
  4. Check the exact spelling and that the command string wasn't truncated by your client.

Example fix

// before
target select 4242
// after
target switch 4242
Defensive patterns

Strategy: validation

Validate before calling

validSubcommands := map[string]bool{"list": true, "follow-exec": true, "switch": true}
sub := strings.Fields(cmdStr)
if len(sub) < 2 || !validSubcommands[sub[1]] {
    return fmt.Errorf("'target' supports only list, follow-exec, switch")
}

Prevention

When it happens

Trigger: Evaluating 'target foo', 'target select 1234' (instead of switch), 'target detach', or an empty/garbled command string reaching targetCmd via DAP evaluate.

Common situations: Users porting CLI habits from 'dlv' terminal or GDB ('target select', 'detach') into DAP evaluate; frontend constructing 'target <something>' from a dropdown with unsupported actions; whitespace mangling producing an empty subcommand.

Related errors


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