hashicorp/nomad · error
cmd is required, but was empty
Error message
cmd is required, but was empty
What it means
The driver's legacy ExecTask path requires at least one command element; `cmd` is the full argv where cmd[0] is the binary and cmd[1:] its arguments. When an empty slice is passed, the driver rejects it before creating any Docker exec. This is defensive input validation because exec'ing with no binary is meaningless.
Solutions
- Pass a non-empty command, e.g. []string{"ls", "-la"}.
- Validate job/task command fields before dispatching exec.
- Guard the call site: return your own validation error if len(cmd) == 0.
Example fix
// before
driver.ExecTask(taskID, []string{}, 5*time.Second)
// after
driver.ExecTask(taskID, []string{"/bin/sh", "-c", "echo hi"}, 5*time.Second) Defensive patterns
Strategy: validation
Validate before calling
if len(cmd) == 0 { return errors.New("cmd must contain at least a binary") } Prevention
- Always construct cmd as [binary, arg1, arg2, ...].
- Validate job command fields at submission time.
- Guard template expansion so empty commands fail early.
When it happens
Trigger: Calling driver.ExecTask(taskID, []string{}, timeout) or ExecTask(taskID, nil, timeout).
Common situations: Job spec with an empty `command` list; templating produced an empty argv; code path that split a command string yielding zero tokens.
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
- command is required but was empty
- cannot apply allowed_modes configuration
- cannot apply allowed_modes configuration
- cannot apply allowed_modes configuration
- cannot apply allowed_modes configuration
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/0682b6709c2d657d.
Report an issue: GitHub.
Appendix: source
Thrown at drivers/docker/driver.go:1920
if err != nil {
return fmt.Errorf("failed to parse signal: %v", err)
}
// TODO: review whether we can timeout in this and other Docker API
// calls without breaking the expected client behavior.
// see https://github.com/hashicorp/nomad/issues/9503
_, err = h.dockerClient.ContainerKill(d.ctx, h.containerID, mclient.ContainerKillOptions{Signal: signal})
return err
}
func (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {
h, ok := d.tasks.Get(taskID)
if !ok {
return nil, drivers.ErrTaskNotFound
}
if len(cmd) == 0 {
return nil, fmt.Errorf("cmd is required, but was empty")
}
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
return h.Exec(ctx, cmd[0], cmd[1:])
}
var _ drivers.ExecTaskStreamingDriver = (*Driver)(nil)
func (d *Driver) ExecTaskStreaming(ctx context.Context, taskID string, opts *drivers.ExecOptions) (*drivers.ExitResult, error) {
defer opts.Stdout.Close()
defer opts.Stderr.Close()
done := make(chan interface{})
defer close(done)
h, ok := d.tasks.Get(taskID)View on GitHub (pinned to 482b49bf1a)