{"record":{"id":"0682b6709c2d657d","repo":"hashicorp/nomad","slug":"cmd-is-required-but-was-empty","errorCode":null,"errorMessage":"cmd is required, but was empty","messagePattern":"cmd is required, but was empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":1920,"sourceCode":"\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse signal: %v\", err)\n\t}\n\n\t// TODO: review whether we can timeout in this and other Docker API\n\t// calls without breaking the expected client behavior.\n\t// see https://github.com/hashicorp/nomad/issues/9503\n\t_, err = h.dockerClient.ContainerKill(d.ctx, h.containerID, mclient.ContainerKillOptions{Signal: signal})\n\treturn err\n}\n\nfunc (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {\n\th, ok := d.tasks.Get(taskID)\n\tif !ok {\n\t\treturn nil, drivers.ErrTaskNotFound\n\t}\n\n\tif len(cmd) == 0 {\n\t\treturn nil, fmt.Errorf(\"cmd is required, but was empty\")\n\t}\n\n\tctx, cancel := context.WithTimeout(context.Background(), timeout)\n\tdefer cancel()\n\n\treturn h.Exec(ctx, cmd[0], cmd[1:])\n}\n\nvar _ drivers.ExecTaskStreamingDriver = (*Driver)(nil)\n\nfunc (d *Driver) ExecTaskStreaming(ctx context.Context, taskID string, opts *drivers.ExecOptions) (*drivers.ExitResult, error) {\n\tdefer opts.Stdout.Close()\n\tdefer opts.Stderr.Close()\n\n\tdone := make(chan interface{})\n\tdefer close(done)\n\n\th, ok := d.tasks.Get(taskID)","sourceCodeStart":1902,"sourceCodeEnd":1938,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L1902-L1938","documentation":"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.","triggerScenarios":"Calling driver.ExecTask(taskID, []string{}, timeout) or ExecTask(taskID, nil, timeout).","commonSituations":"Job spec with an empty `command` list; templating produced an empty argv; code path that split a command string yielding zero tokens.","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."],"exampleFix":"// before\ndriver.ExecTask(taskID, []string{}, 5*time.Second)\n// after\ndriver.ExecTask(taskID, []string{\"/bin/sh\", \"-c\", \"echo hi\"}, 5*time.Second)","handlingStrategy":"validation","validationCode":"if len(cmd) == 0 { return errors.New(\"cmd must contain at least a binary\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always construct cmd as [binary, arg1, arg2, ...].","Validate job command fields at submission time.","Guard template expansion so empty commands fail early."],"tags":["docker","exec","validation"],"backgroundTag":"missing-required-argument","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"}