{"record":{"id":"a818401df07a0b75","repo":"hashicorp/nomad","slug":"command-is-not-present","errorCode":null,"errorMessage":"command is not present","messagePattern":"command is not present","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"client/alloc_endpoint.go","lineNumber":321,"sourceCode":"\t// If an action is present, go find the command and args\n\tif req.Action != \"\" {\n\t\ttask := alloc.LookupTask(req.Task)\n\t\tif task == nil {\n\t\t\treturn new(int64(http.StatusBadRequest)),\n\t\t\t\tfmt.Errorf(\"task %s not found in allocation %s\", req.Task, alloc.ID)\n\t\t}\n\t\tjobAction := task.GetAction(req.Action)\n\t\tif jobAction == nil {\n\t\t\treturn new(int64(http.StatusBadRequest)),\n\t\t\t\tfmt.Errorf(\"action %s not found in task %s\", req.Action, req.Task)\n\t\t}\n\n\t\t// append both Command and Args\n\t\treq.Cmd = append([]string{jobAction.Command}, jobAction.Args...)\n\t}\n\n\tif len(req.Cmd) == 0 {\n\t\treturn new(int64(400)), errors.New(\"command is not present\")\n\t}\n\n\tcapabilities, err := ar.GetTaskDriverCapabilities(req.Task)\n\tif err != nil {\n\t\tcode := new(int64(500))\n\t\tif nstructs.IsErrUnknownAllocation(err) {\n\t\t\tcode = new(int64(404))\n\t\t}\n\n\t\treturn code, err\n\t}\n\n\t// check node access\n\tif capabilities.FSIsolation == fsisolation.None {\n\t\texec := aclObj.AllowNsOp(alloc.Namespace, acl.NamespaceCapabilityAllocNodeExec)\n\t\tif !exec {\n\t\t\treturn nil, nstructs.ErrPermissionDenied\n\t\t}","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/client/alloc_endpoint.go#L303-L339","documentation":"The allocation exec endpoint requires an actual command to run. The command is assembled from the exec request's cmd/command plus args (and from job action definitions in the job action path). If the assembled req.Cmd slice is empty, there is nothing to execute, so the handler returns this 400 error before contacting the task driver.","triggerScenarios":"POSTing to the alloc exec API with no 'cmd' and no 'args' (or an exec job action that defines neither Command nor Args, leaving req.Cmd empty).","commonSituations":"Client SDKs serializing an empty command array; CLI tools like 'nomad alloc exec <alloc>' invoked without a command; job action specs missing the command field; templated scripts where the command variable expands to empty.","solutions":["Pass a non-empty cmd (first element is the binary) in the exec request","If using a job action, define its Command (and optional Args) in the job spec","Fix the caller/CLI wrapper to reject empty commands before calling the API","Validate user input so blank/whitespace commands are rejected client-side"],"exampleFix":"// before\n{\"Task\":\"web\",\"Cmd\":[]}\n// after\n{\"Task\":\"web\",\"Cmd\":[\"/bin/sh\",\"-c\",\"ls\"]}","handlingStrategy":"validation","validationCode":"if len(cmd) == 0 && len(args) == 0 {\n  return errors.New(\"exec requires a command: provide cmd/args or a job action with a Command\")\n}","typeGuard":"func hasCommand(cmd []string) bool { return len(cmd) > 0 && strings.TrimSpace(cmd[0]) != \"\" }","tryCatchPattern":"err := client.Allocations().Exec(ctx, alloc, task, false, cmd, stdin, stdout, stderr, nil)\nif err != nil && strings.Contains(err.Error(), \"command is not present\") {\n  return fmt.Errorf(\"no command given: usage: nomad alloc exec <alloc> <task> <cmd...>\")\n}","preventionTips":["Validate that cmd[0] is non-empty before calling the exec API","Ensure job actions always define Command in the job spec","Reject blank/whitespace-only commands in CLI/SDK layers"],"tags":["api","validation","exec"],"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"}