{"record":{"id":"35aa10ae51125ab5","repo":"hashicorp/nomad","slug":"error-cmd-must-have-at-least-one-value-35aa10","errorCode":null,"errorMessage":"error cmd must have at least one value","messagePattern":"error cmd must have at least one value","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/rawexec/driver.go","lineNumber":611,"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\t}\n\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":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/rawexec/driver.go#L593-L629","documentation":"ExecTask runs a one-off command inside a running task. raw_exec validates the command slice up front and rejects an empty cmd slice with 'error cmd must have at least one value' before any task lookup or executor RPC.","triggerScenarios":"Calling ExecTask(taskID, []string{}, timeout) — i.e., the cmd parameter has length 0.","commonSituations":"Building the command from a config/env array or split() that produced zero elements; passing a nil slice; upstream caller passing an empty exec block from a job spec.","solutions":["Ensure the cmd slice contains at least the binary path before calling ExecTask","Validate len(cmd) > 0 in the calling code and fail fast with a clearer message","Fix the source of the empty array (config parsing, string split on empty input)"],"exampleFix":"// before\ncmd := strings.Fields(cfg.ExecCommand) // may be empty\nres, err := driver.ExecTask(taskID, cmd, 5*time.Second)\n// after\nif len(cmd) == 0 { return nil, errors.New(\"exec command is empty\") }\nres, err := driver.ExecTask(taskID, cmd, 5*time.Second)","handlingStrategy":"validation","validationCode":"if len(cmd) == 0 {\n    return fmt.Errorf(\"exec: command must contain at least the binary path\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := driver.ExecTask(id, cmd, timeout); err != nil {\n    if strings.Contains(err.Error(), \"cmd must have at least one value\") {\n        // fix caller argument assembly\n    }\n}","preventionTips":["Validate argv length before any driver exec API call","Guard against empty results from strings.Fields/Split on user config","Fail fast at config parse time when exec commands are empty"],"tags":["validation","exec","argument-validation","nomad"],"backgroundTag":"empty-argument-list","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"}