{"record":{"id":"d39d92a3cb791336","repo":"hashicorp/nomad","slug":"missing-job-id-d39d92","errorCode":null,"errorMessage":"missing job ID","messagePattern":"missing job ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/job_endpoint.go","lineNumber":1521,"sourceCode":"\t\treturn err\n\t}\n\tj.srv.MeasureRPCRate(\"job\", structs.RateMetricList, args)\n\tif authErr != nil {\n\t\treturn structs.ErrPermissionDenied\n\t}\n\tdefer metrics.MeasureSince([]string{\"nomad\", \"job\", \"allocations\"}, time.Now())\n\n\t// Check for read-job permissions\n\tif aclObj, err := j.srv.ResolveACL(args); err != nil {\n\t\treturn err\n\t} else if !aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilityReadJob) {\n\t\treturn structs.ErrPermissionDenied\n\t}\n\n\t// Ensure JobID is set otherwise everything works and never returns\n\t// allocations which can hide bugs in request code.\n\tif args.JobID == \"\" {\n\t\treturn fmt.Errorf(\"missing job ID\")\n\t}\n\n\t// Setup the blocking query\n\topts := blockingOptions{\n\t\tqueryOpts: &args.QueryOptions,\n\t\tqueryMeta: &reply.QueryMeta,\n\t\trun: func(ws memdb.WatchSet, state *state.StateStore) error {\n\t\t\t// Capture the allocations\n\t\t\tallocs, err := state.AllocsByJob(ws, args.RequestNamespace(), args.JobID, args.All)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\t// Convert to stubs\n\t\t\tif len(allocs) > 0 {\n\t\t\t\treply.Allocations = make([]*structs.AllocListStub, 0, len(allocs))\n\t\t\t\tfor _, alloc := range allocs {\n\t\t\t\t\treply.Allocations = append(reply.Allocations, alloc.Stub(nil))","sourceCodeStart":1503,"sourceCodeEnd":1539,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/job_endpoint.go#L1503-L1539","documentation":"Job.Allocations was called without JobID set. The endpoint deliberately rejects empty JobIDs because the query would return no allocations and could mask request-construction bugs, so it fails fast with 'missing job ID'.","triggerScenarios":"GET /v1/job//allocations or client.Jobs().Allocations(jobID=\"\", ...) — any AllocsRequest with args.JobID == \"\" after ACL/namespace checks pass, at nomad/job_endpoint.go:1521.","commonSituations":"Variable holding the job ID is empty due to a failed template or unset env var; CLI flag omitted and default is empty string; REST client concatenating an empty path segment; pagination code dropping the ID field.","solutions":["Set JobID in the request before calling the allocations endpoint.","Resolve the job ID from 'nomad job status' or the jobs list API if it comes from automation.","Add a client-side empty-string check so failures surface at the call site, not the server.","Check the templating/env pipeline that supplies the job ID for silent empty values."],"exampleFix":"// before\nallocs, _, err := client.Jobs().Allocations(\"\", false, nil)\n// after\nif jobID == \"\" {\n    return fmt.Errorf(\"job ID is required\")\n}\nallocs, _, err := client.Jobs().Allocations(jobID, false, nil)","handlingStrategy":"validation","validationCode":"if jobID == \"\" {\n    return fmt.Errorf(\"cannot list allocations: jobID is empty\")\n}\nallocs, _, err := client.Jobs().Allocations(jobID, all, nil)","typeGuard":"func jobIDSet(id string) bool { return strings.TrimSpace(id) != \"\" }","tryCatchPattern":"allocs, _, err := client.Jobs().Allocations(jobID, false, nil)\nif err != nil && strings.Contains(err.Error(), \"missing job ID\") {\n    return fmt.Errorf(\"check the job-id flag/env: got empty value\")\n}","preventionTips":["Fail fast client-side when required IDs are empty strings.","Trace env/template variables that feed job IDs for silent empty values.","Use the jobs list API to resolve IDs rather than assuming they exist."],"tags":["nomad","request-validation","missing-parameter"],"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"}