go-delve/delve · error

unknown command 'target %s'

Error message

unknown command 'target %s'

What it means

`target` supports only the subcommands `follow-exec`, `switch`, or nothing. Any other first token falls into the default case and produces this error naming the unknown subcommand.

Source

Thrown at pkg/terminal/command.go:3602

		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 {
		thing = strings.ToUpper(string(thing[0])) + thing[1:]
	}
	id := bp.Name
	if id == "" {
		id = strconv.Itoa(bp.ID)
	}

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Use `target switch <pid>` to switch targets
  2. Use `target follow-exec [-on|-off|-regex <pattern>]` to control exec following
  3. Run `help target` to see valid subcommands

Example fix

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

Strategy: try-catch

Try / catch

switch sub {
case "follow-exec", "switch", "":
    // proceed
default:
    return fmt.Errorf("unknown target subcommand %q", sub)
}

Prevention

When it happens

Trigger: Running e.g. `target list`, `target 4242`, or any misspelled subcommand at the Delve prompt.

Common situations: Guessing subcommand names (`list`, `show`, `select`); abbreviating `follow-exec` incorrectly; expecting `target <pid>` to switch directly instead of `target switch <pid>`.

Related errors


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