hashicorp/nomad · error

no exec command is configured

Error message

no exec command is configured

What it means

The mock driver's ExecTaskStreaming requires a pre-configured exec command (h.execCommand); if none was set on the mock, it returns this error instead of executing anything. This makes missing mock configuration explicit during tests.

Source

Thrown at drivers/mock/driver.go:667

	res := drivers.ExecTaskResult{
		Stdout:     []byte(fmt.Sprintf("Exec(%q, %q)", h.taskConfig.Name, cmd)),
		ExitResult: &drivers.ExitResult{},
	}
	return &res, nil
}

var _ drivers.ExecTaskStreamingDriver = (*Driver)(nil)

func (d *Driver) ExecTaskStreaming(ctx context.Context, taskID string, execOpts *drivers.ExecOptions) (*drivers.ExitResult, error) {
	h, ok := d.tasks.Get(taskID)
	if !ok {
		return nil, drivers.ErrTaskNotFound
	}

	d.logger.Info("executing task", "command", h.execCommand, "task_id", taskID)

	if h.execCommand == nil {
		return nil, errors.New("no exec command is configured")
	}

	cancelCh := make(chan struct{})
	exitTimer := make(chan time.Time)

	cmd := *h.execCommand
	if len(execOpts.Command) == 1 && execOpts.Command[0] == "showinput" {
		stdin, _ := io.ReadAll(execOpts.Stdin)
		cmd = Command{
			RunFor: "1ms",
			StdoutString: fmt.Sprintf("TTY: %v\nStdin:\n%s\n",
				execOpts.Tty,
				stdin,
			),
		}
	}

	return runCommand(cmd, execOpts.Stdout, execOpts.Stderr, cancelCh, exitTimer, d.logger), nil

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Configure the mock driver's exec command before calling ExecTaskStreaming
  2. If exec isn't under test, skip the exec path or use a driver that supports exec
  3. Update the test fixture to copy a *exec.Cmd into the mock's execCommand field

Example fix

// before
mockDriver := testutil.NewMockDriver()
// after
mockDriver := testutil.NewMockDriver()
mockDriver.DriverConfig.ExecCommand = &exec.Cmd{Path: "/bin/true"}
Defensive patterns

Strategy: validation

Validate before calling

if mockExecCommand == nil {
    t.Fatal("mock driver execCommand must be configured before ExecTaskStreaming")
}

Type guard

func execConfigured(h *mockTaskHandle) bool { return h.execCommand != nil }

Try / catch

if err := execTaskStreaming(...); err != nil {
    if strings.Contains(err.Error(), "no exec command is configured") {
        t.Fatalf("test setup error: configure mock driver execCommand; %v", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling ExecTaskStreaming against a mock driver task whose handler was created without setting execCommand — e.g. using the mock driver for exec tests without calling the setup that assigns the command.

Common situations: Test harnesses exercising `nomad alloc exec`-style flows against the mock driver; tests written before the mock's exec support was configured; refactors that dropped the execCommand assignment.

Related errors


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