hashicorp/nomad · error
error cmd must have at least one value
Error message
error cmd must have at least one value
What it means
ExecTask validates its cmd argument before doing anything else: if the command slice is empty (len(cmd) == 0) there is nothing to execute, so the driver returns this error immediately. It is a pure input-validation error — no task lookup or executor interaction has happened yet.
Source
Thrown at drivers/java/driver.go:708
func (d *Driver) SignalTask(taskID string, signal string) error {
handle, ok := d.tasks.Get(taskID)
if !ok {
return drivers.ErrTaskNotFound
}
sig := os.Interrupt
if s, ok := signals.SignalLookup[signal]; ok {
sig = s
} else {
d.logger.Warn("unknown signal to send to task, using SIGINT instead", "signal", signal, "task_id", handle.taskConfig.ID)
}
return handle.exec.Signal(sig)
}
func (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {
if len(cmd) == 0 {
return nil, fmt.Errorf("error cmd must have at least one value")
}
handle, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound
}
out, exitCode, err := handle.exec.Exec(time.Now().Add(timeout), cmd[0], cmd[1:])
if err != nil {
return nil, err
}
return &drivers.ExecTaskResult{
Stdout: out,
ExitResult: &drivers.ExitResult{
ExitCode: exitCode,
},
}, nil
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Pass a non-empty cmd slice, e.g. []string{"/bin/sh", "-c", "echo hi"}
- Validate the command list at the call site before invoking ExecTask
- If the command comes from config/user input, trim and split it and reject empty results with a clearer upstream message
- Ensure the intended binary path is actually populated (empty env/variable expansion yields an empty slice)
Example fix
// before: empty command slips through to ExecTask
var cmd []string
res, err := driver.ExecTask(taskID, cmd, 30*time.Second)
// after: validate and provide a real command
if len(cmd) == 0 {
return fmt.Errorf("exec command is required")
}
cmd = []string{"/bin/jps", "-l"}
res, err := driver.ExecTask(taskID, cmd, 30*time.Second) Defensive patterns
Strategy: validation
Validate before calling
if len(cmd) == 0 {
return nil, fmt.Errorf("exec command is required")
} Type guard
func hasCommand(cmd []string) bool {
return len(cmd) > 0 && strings.TrimSpace(cmd[0]) != ""
} Try / catch
res, err := driver.ExecTask(taskID, cmd, timeout)
if err != nil && strings.Contains(err.Error(), "cmd must have at least one value") {
return nil, fmt.Errorf("exec command was empty; provide a command list")
} Prevention
- Validate command slices at the call site before calling ExecTask
- Reject empty/whitespace-only exec command config upstream
- Check variable expansion that feeds the command list
When it happens
Trigger: Calling Driver.ExecTask(taskID, cmd, timeout) with a nil or zero-length cmd slice, e.g. building the command from a split of an empty string or omitting exec command arguments in the calling code.
Common situations: Automation/tooling passing an unvalidated command array, config where the exec command field was empty or whitespace-only, or variable expansion producing an empty list.
Related errors
- Node ID must contain at least two characters.
- invalid host_volumes limit: %v
- default_pid_mode must be %q or %q, got %q
- default_ipc_mode must be %q or %q, got %q
- allow_caps configured with capabilities not supported by sys
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/accb1fa40f419cf0.
Report an issue: GitHub.