{"record":{"id":"c02f5effeabf46b6","repo":"hashicorp/nomad","slug":"no-exec-command-is-configured","errorCode":null,"errorMessage":"no exec command is configured","messagePattern":"no exec command is configured","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/mock/driver.go","lineNumber":667,"sourceCode":"\tres := drivers.ExecTaskResult{\n\t\tStdout:     []byte(fmt.Sprintf(\"Exec(%q, %q)\", h.taskConfig.Name, cmd)),\n\t\tExitResult: &drivers.ExitResult{},\n\t}\n\treturn &res, nil\n}\n\nvar _ drivers.ExecTaskStreamingDriver = (*Driver)(nil)\n\nfunc (d *Driver) ExecTaskStreaming(ctx context.Context, taskID string, execOpts *drivers.ExecOptions) (*drivers.ExitResult, error) {\n\th, ok := d.tasks.Get(taskID)\n\tif !ok {\n\t\treturn nil, drivers.ErrTaskNotFound\n\t}\n\n\td.logger.Info(\"executing task\", \"command\", h.execCommand, \"task_id\", taskID)\n\n\tif h.execCommand == nil {\n\t\treturn nil, errors.New(\"no exec command is configured\")\n\t}\n\n\tcancelCh := make(chan struct{})\n\texitTimer := make(chan time.Time)\n\n\tcmd := *h.execCommand\n\tif len(execOpts.Command) == 1 && execOpts.Command[0] == \"showinput\" {\n\t\tstdin, _ := io.ReadAll(execOpts.Stdin)\n\t\tcmd = Command{\n\t\t\tRunFor: \"1ms\",\n\t\t\tStdoutString: fmt.Sprintf(\"TTY: %v\\nStdin:\\n%s\\n\",\n\t\t\t\texecOpts.Tty,\n\t\t\t\tstdin,\n\t\t\t),\n\t\t}\n\t}\n\n\treturn runCommand(cmd, execOpts.Stdout, execOpts.Stderr, cancelCh, exitTimer, d.logger), nil","sourceCodeStart":649,"sourceCodeEnd":685,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/mock/driver.go#L649-L685","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Configure the mock driver's exec command before calling ExecTaskStreaming","If exec isn't under test, skip the exec path or use a driver that supports exec","Update the test fixture to copy a *exec.Cmd into the mock's execCommand field"],"exampleFix":"// before\nmockDriver := testutil.NewMockDriver()\n// after\nmockDriver := testutil.NewMockDriver()\nmockDriver.DriverConfig.ExecCommand = &exec.Cmd{Path: \"/bin/true\"}","handlingStrategy":"validation","validationCode":"if mockExecCommand == nil {\n    t.Fatal(\"mock driver execCommand must be configured before ExecTaskStreaming\")\n}","typeGuard":"func execConfigured(h *mockTaskHandle) bool { return h.execCommand != nil }","tryCatchPattern":"if err := execTaskStreaming(...); err != nil {\n    if strings.Contains(err.Error(), \"no exec command is configured\") {\n        t.Fatalf(\"test setup error: configure mock driver execCommand; %v\", err)\n    }\n    return err\n}","preventionTips":["Centralize mock driver setup so execCommand is always assigned","Add test assertions that the mock handle has an exec command before exec tests","Skip exec-path tests when the driver under test cannot exec"],"tags":["nomad","mock-driver","testing","exec"],"backgroundTag":"missing-test-fixture-config","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}