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 one-off command inside a running task. raw_exec validates the command slice up front and rejects an empty cmd slice with 'error cmd must have at least one value' before any task lookup or executor RPC.

Source

Thrown at drivers/rawexec/driver.go:611

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

  1. Ensure the cmd slice contains at least the binary path before calling ExecTask
  2. Validate len(cmd) > 0 in the calling code and fail fast with a clearer message
  3. Fix the source of the empty array (config parsing, string split on empty input)

Example fix

// before
cmd := strings.Fields(cfg.ExecCommand) // may be empty
res, err := driver.ExecTask(taskID, cmd, 5*time.Second)
// after
if len(cmd) == 0 { return nil, errors.New("exec command is empty") }
res, err := driver.ExecTask(taskID, cmd, 5*time.Second)
Defensive patterns

Strategy: validation

Validate before calling

if len(cmd) == 0 {
    return fmt.Errorf("exec: command must contain at least the binary path")
}

Try / catch

if _, err := driver.ExecTask(id, cmd, timeout); err != nil {
    if strings.Contains(err.Error(), "cmd must have at least one value") {
        // fix caller argument assembly
    }
}

Prevention

When it happens

Trigger: Calling ExecTask(taskID, []string{}, timeout) — i.e., the cmd parameter has length 0.

Common situations: Building the command from a config/env array or split() that produced zero elements; passing a nil slice; upstream caller passing an empty exec block from a job spec.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/35aa10ae51125ab5. Report an issue: GitHub.