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 runs a command inside a running task's environment. Before looking up the task, it validates that the cmd slice is non-empty; passing an empty slice is rejected with this error because there is no command to execute.
Source
Thrown at drivers/exec/driver.go:698
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
}
args := []string{}
if len(cmd) > 1 {
args = cmd[1:]
}
out, exitCode, err := handle.exec.Exec(time.Now().Add(timeout), cmd[0], args)
if err != nil {
return nil, err
}
return &drivers.ExecTaskResult{
Stdout: out,View on GitHub (pinned to 482b49bf1a)
Solutions
- Ensure the command slice contains at least the binary path, e.g. []string{"/bin/ls"}.
- Add an up-front length check on the command before invoking ExecTask.
- Fix the upstream logic or config that yields an empty command value.
Example fix
// before
driver.ExecTask(taskID, []string{}, time.Minute)
// after
cmd := []string{"/bin/echo", "hello"}
if len(cmd) == 0 {
return fmt.Errorf("command required")
}
driver.ExecTask(taskID, cmd, time.Minute) Defensive patterns
Strategy: validation
Validate before calling
if len(cmd) == 0 {
return fmt.Errorf("ExecTask requires a non-empty command")
} Type guard
func validCmd(cmd []string) bool { return len(cmd) > 0 && cmd[0] != "" } Try / catch
if _, err := driver.ExecTask(taskID, cmd, timeout); err != nil && strings.Contains(err.Error(), "cmd must have at least one value") {
return fmt.Errorf("command argument was empty: %w", err)
} Prevention
- Validate argv length before any exec-style call.
- Don't pass user/config-supplied command strings unchecked.
- Prefer explicit command construction over variadic expansion.
When it happens
Trigger: Calling driver.ExecTask(taskID, []string{}, timeout) — an empty or nil command slice.
Common situations: Dynamic command construction where variables expand to nothing; config/template producing an empty command; copy-paste calling ExecTask with the wrong variable.
Related errors
- default_pid_mode must be %q or %q, got %q
- default_ipc_mode must be %q or %q, got %q
- pid_mode must be %q or %q, got %q
- ipc_mode must be %q or %q, got %q
- work_dir must be absolute but got relative path %q
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/ec365aaa949d9ec8.
Report an issue: GitHub.