go-delve/delve · error

needs to be followed by an expression

Error message

%s %s needs to be followed by an expression

What it means

readGoroutinesFilter accepts filters that require an argument (curloc, userloc, label, function, file, line). If such a filter kind is followed by no expression, this error is thrown naming both tokens. Filters like 'running' and 'user' are exempt and return early.

Solutions

  1. Add the expression after the kind, e.g. 'goroutines -with function main.worker'.
  2. Quote expressions containing spaces: 'goroutines -with label "my worker"'.
  3. Use 'running' or 'user' if you did not intend to pass a value.

Example fix

// before
cmd.ProcessLine("goroutines -with label")
// after
cmd.ProcessLine("goroutines -with label worker-")
Defensive patterns

Strategy: validation

Validate before calling

func filterNeedsExpr(kind string) bool {
	return kind != "running" && kind != "user"
}
// if filterNeedsExpr(kind), ensure an expression token follows before calling the API

Try / catch

if _, err := api.ParseGoroutineArgs(args); err != nil {
	return fmt.Errorf("filter needs expression: %v", err)
}

Prevention

When it happens

Trigger: Calling ParseGoroutineArgs with 'goroutines -with label' (kind parsed but no expression follows) - the kind itself was valid but its required expression is missing.

Common situations: A value containing spaces that the shell consumed; forgetting the label/regex after the kind; empty trailing token stripped by shell word-splitting.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at service/api/command.go:162

	default:
		return GoroutineFieldNone, fmt.Errorf("unrecognized argument to %s %s", args[i-1], args[i])
	}
}

func readGoroutinesFilter(args []string, pi *int) (*ListGoroutinesFilter, error) {
	r := new(ListGoroutinesFilter)
	var err error
	r.Kind, err = readGoroutinesFilterKind(args, *pi+1)
	if err != nil {
		return nil, err
	}
	*pi++
	switch r.Kind {
	case GoroutineRunning, GoroutineUser:
		return r, nil
	}
	if *pi+1 >= len(args) {
		return nil, fmt.Errorf("%s %s needs to be followed by an expression", args[*pi-1], args[*pi])
	}
	r.Arg = args[*pi+1]
	*pi++

	return r, nil
}

type ExamineMemoryArgs struct {
	Operand string
	Count   int64
	Size    int64
	IsExpr  bool
	Format  byte
	RawOut  bool
}

func ParseExamineMemoryArg(argstr string) (*ExamineMemoryArgs, error) {
	// default args

View on GitHub (pinned to a23773e6c3)