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

  1. Pass a non-empty cmd slice, e.g. []string{"/bin/sh", "-c", "echo hi"}
  2. Validate the command list at the call site before invoking ExecTask
  3. If the command comes from config/user input, trim and split it and reject empty results with a clearer upstream message
  4. 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

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


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