go-delve/delve · error
not enough arguments after -chan
Error message
not enough arguments after -chan
What it means
ParseGoroutineArgs parses arguments to the goroutines command. The -chan flag expects a following channel expression; when -chan is the last token (i >= len(args) after the increment), there is no filter value and parsing fails with this error. It guards ListGoroutinesFilter construction from a missing argument.
Source
Thrown at service/api/command.go:106
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++
if group.GroupBy == GoroutineLabel {
if i+1 >= len(args) {
return nil, GoroutineGroupingOptions{}, 0, 0, 0, 0, "", fmt.Errorf("wrong argument: '%s'", arg)
}
group.GroupByKey = args[i+1]
i++
}
batchSize = 0 // grouping only works well if run on all goroutines
case "-chan":
i++
if i >= len(args) {
return nil, GoroutineGroupingOptions{}, 0, 0, 0, 0, "", errors.New("not enough arguments after -chan")
}
filters = append(filters, ListGoroutinesFilter{Kind: GoroutineWaitingOnChannel, Arg: args[i]})
case "-exec":
flags |= PrintGoroutinesExec
cmd = strings.Join(args[i+1:], " ")
i = len(args)
case "":
// nothing to do
default:
return nil, GoroutineGroupingOptions{}, 0, 0, 0, 0, "", fmt.Errorf("wrong argument: '%s'", arg)
}
}
return filters, group, fgl, flags, depth, batchSize, cmd, nil
}
func readGoroutinesFilterKind(args []string, i int) (GoroutineField, error) {View on GitHub (pinned to a23773e6c3)
Solutions
- Provide a channel expression after the flag: goroutines -chan myCh
- If the channel name comes from a variable, ensure it is non-empty before building the command
- Use `goroutines -help` (or `help goroutines`) to review valid flags: -chan, -exec, -group, etc.
Example fix
// before
args := []string{"goroutines", "-chan"}
// after
args := []string{"goroutines", "-chan", "ch"} Defensive patterns
Strategy: validation
Validate before calling
# shell: fail early when the channel arg is missing
CH=${CH:?"-chan requires a channel expression"}
dlv_ex_cmd="goroutines -chan $CH" Type guard
func hasValueAfter(args []string, flag string) bool {
for i, a := range args {
if a == flag {
return i+1 < len(args)
}
}
return false
} Prevention
- Always write the channel expression on the same command line: goroutines -chan ch
- Quote channel expressions containing spaces
- In scripts, use ${VAR:?msg} to abort on empty expansions
- Run `help goroutines` to confirm flag syntax before composing complex commands
When it happens
Trigger: Invoking `goroutines -chan` with nothing after the flag, e.g. typing `goroutines -chan` at the dlv prompt or calling the RPC/API path where args ends with "-chan". Also occurs when quoting mistakes swallow the intended channel expression.
Common situations: Users forgetting the channel variable after -chan; shell scripts dropping the last argument due to an empty variable expansion (e.g. `goroutines -chan $CH` with CH unset); copy-pasting partial commands from docs.
Related errors
- expected argument after -fmt
- expected argument after -count/-len
- wrong argument: '%s'
- could not find goroutine array
- command not available
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/460088f9441310ae.
Report an issue: GitHub.