{"record":{"id":"accb1fa40f419cf0","repo":"hashicorp/nomad","slug":"error-cmd-must-have-at-least-one-value-accb1f","errorCode":null,"errorMessage":"error cmd must have at least one value","messagePattern":"error cmd must have at least one value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/java/driver.go","lineNumber":708,"sourceCode":"func (d *Driver) SignalTask(taskID string, signal string) error {\n\thandle, ok := d.tasks.Get(taskID)\n\tif !ok {\n\t\treturn drivers.ErrTaskNotFound\n\t}\n\n\tsig := os.Interrupt\n\tif s, ok := signals.SignalLookup[signal]; ok {\n\t\tsig = s\n\t} else {\n\t\td.logger.Warn(\"unknown signal to send to task, using SIGINT instead\", \"signal\", signal, \"task_id\", handle.taskConfig.ID)\n\n\t}\n\treturn handle.exec.Signal(sig)\n}\n\nfunc (d *Driver) ExecTask(taskID string, cmd []string, timeout time.Duration) (*drivers.ExecTaskResult, error) {\n\tif len(cmd) == 0 {\n\t\treturn nil, fmt.Errorf(\"error cmd must have at least one value\")\n\t}\n\thandle, ok := d.tasks.Get(taskID)\n\tif !ok {\n\t\treturn nil, drivers.ErrTaskNotFound\n\t}\n\n\tout, exitCode, err := handle.exec.Exec(time.Now().Add(timeout), cmd[0], cmd[1:])\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &drivers.ExecTaskResult{\n\t\tStdout: out,\n\t\tExitResult: &drivers.ExitResult{\n\t\t\tExitCode: exitCode,\n\t\t},\n\t}, nil\n}","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/java/driver.go#L690-L726","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass a non-empty cmd slice, e.g. []string{\"/bin/sh\", \"-c\", \"echo hi\"}","Validate the command list at the call site before invoking ExecTask","If the command comes from config/user input, trim and split it and reject empty results with a clearer upstream message","Ensure the intended binary path is actually populated (empty env/variable expansion yields an empty slice)"],"exampleFix":"// before: empty command slips through to ExecTask\nvar cmd []string\nres, err := driver.ExecTask(taskID, cmd, 30*time.Second)\n// after: validate and provide a real command\nif len(cmd) == 0 {\n    return fmt.Errorf(\"exec command is required\")\n}\ncmd = []string{\"/bin/jps\", \"-l\"}\nres, err := driver.ExecTask(taskID, cmd, 30*time.Second)","handlingStrategy":"validation","validationCode":"if len(cmd) == 0 {\n    return nil, fmt.Errorf(\"exec command is required\")\n}","typeGuard":"func hasCommand(cmd []string) bool {\n    return len(cmd) > 0 && strings.TrimSpace(cmd[0]) != \"\"\n}","tryCatchPattern":"res, err := driver.ExecTask(taskID, cmd, timeout)\nif err != nil && strings.Contains(err.Error(), \"cmd must have at least one value\") {\n    return nil, fmt.Errorf(\"exec command was empty; provide a command list\")\n}","preventionTips":["Validate command slices at the call site before calling ExecTask","Reject empty/whitespace-only exec command config upstream","Check variable expansion that feeds the command list"],"tags":["nomad","java-driver","exec-task","input-validation","argument-error"],"backgroundTag":"empty-command-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"}