go-delve/delve · error

wrong argument: '%s'

Error message

wrong argument: '%s'

What it means

`ParseGoroutineArgs` parses the argument string of the `goroutines` command. For the `-w`/`-with` filter flag, the following tokens are parsed by `readGoroutinesFilter`; if that fails (missing or malformed filter, e.g. no kind=value pair), the parser returns `wrong argument: '<arg>'` naming the flag. The error is a parse failure of the goroutines command-line syntax, not an RPC error.

Source

Thrown at service/api/command.go:75

		case "-s":
			fgl = FglStart
		case "-l":
			flags |= PrintGoroutinesLabels
		case "-t":
			flags |= PrintGoroutinesStack
			// optional depth argument
			if i+1 < len(args) && len(args[i+1]) > 0 {
				n, err := strconv.Atoi(args[i+1])
				if err == nil {
					depth = n
					i++
				}
			}

		case "-w", "-with":
			filter, err := readGoroutinesFilter(args, &i)
			if err != nil {
				return nil, GoroutineGroupingOptions{}, 0, 0, 0, 0, "", fmt.Errorf("wrong argument: '%s'", arg)
			}
			filters = append(filters, *filter)

		case "-wo", "-without":
			filter, err := readGoroutinesFilter(args, &i)
			if err != nil {
				return nil, GoroutineGroupingOptions{}, 0, 0, 0, 0, "", fmt.Errorf("wrong argument: '%s'", arg)
			}
			filter.Negated = true
			filters = append(filters, *filter)

		case "-group":
			var err error
			group.GroupBy, err = readGoroutinesFilterKind(args, i+1)
			if err != nil {
				return nil, GoroutineGroupingOptions{}, 0, 0, 0, 0, "", fmt.Errorf("wrong argument: '%s'", arg)
			}
			i++

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Supply a valid filter after -w, e.g. `goroutines -w running` or `-w userloc=main.main`
  2. Check the supported filter kinds (running, userloc, startloc, label, etc.) in the goroutines command help
  3. Quote arguments containing spaces correctly so the split-on-space parser sees the right tokens

Example fix

// before
goroutines -w
// after
goroutines -w running
Defensive patterns

Strategy: validation

Validate before calling

// before invoking: ensure -w/-with is followed by a parsable filter
tokens := strings.Fields(argstr)
for i, t := range tokens {
    if t == "-w" || t == "-with" {
        if i+1 >= len(tokens) || !strings.Contains(tokens[i+1], "=") && !isFilterKind(tokens[i+1]) {
            return fmt.Errorf("-w requires a filter operand")
        }
    }
}

Try / catch

if err != nil {
    var perr interface{ Error() string }
    if errors.As(err, &perr) && strings.HasPrefix(err.Error(), "wrong argument:") {
        // surface usage help for the goroutines command
    }
}

Prevention

When it happens

Trigger: Passing `-w` or `-with` without a following filter argument, or with a filter that readGoroutinesFilter cannot parse (malformed kind:value, unparseable number, unknown filter kind).

Common situations: Typing `goroutines -w` and forgetting the filter; using a filter kind not in the supported list; quoting problems splitting the arg string on spaces.

Related errors


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