{"record":{"id":"a9d1436511c25c65","repo":"hashicorp/nomad","slug":"error-querying-job-q-s","errorCode":null,"errorMessage":"Error querying job %q: %s","messagePattern":"Error querying job %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/meta.go","lineNumber":335,"sourceCode":"}\n\nfunc (e *NoJobWithPrefixError) Error() string {\n\treturn fmt.Sprintf(\"No job(s) with prefix or ID %q found\", e.Prefix)\n}\n\n// JobByPrefix returns the job that best matches the given prefix. Returns an\n// error if there are no matches or if there are more than one exact match\n// across namespaces.\nfunc (m *Meta) JobByPrefix(client *api.Client, prefix string) (*api.Job, error) {\n\tjobID, namespace, err := m.JobIDByPrefix(client, prefix)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tq := &api.QueryOptions{Namespace: namespace}\n\tjob, _, err := client.Jobs().Info(jobID, q)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error querying job %q: %s\", jobID, err)\n\t}\n\tjob.Namespace = new(namespace)\n\n\treturn job, nil\n}\n\n// JobByPrefixFilterFunc filters jobs during a client-side prefix match. It is\n// the fallback for servers that cannot evaluate the server-side filter expression.\ntype JobByPrefixFilterFunc func(*api.JobListStub) bool\n\n// JobIDByPrefix provides best effort match for the given job prefix.\n// Returns the prefix itself if job prefix search is not allowed and an error\n// if there are no matches or if there are more than one exact match across\n// namespaces.\nfunc (m *Meta) JobIDByPrefix(client *api.Client, prefix string) (string, string, error) {\n\treturn m.jobIDByPrefix(client, prefix, \"\", nil)\n}\n","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/meta.go#L317-L353","documentation":"Returned by JobByPrefix in command/meta.go when client.Jobs().Info(jobID, q) fails after a prefix lookup resolved a candidate job ID. It wraps the API error and names the resolved job ID. Because the ID came from PrefixList, a 404 here usually means the job vanished between the list and info calls or the namespace differs.","triggerScenarios":"Any command that resolves a job by ID/prefix (e.g. `nomad job status web`) where Jobs().Info errors: exact ID does not exist (404), ACL token cannot read jobs in the given namespace (403), namespace flag/env targets a nonexistent namespace, or connection failure.","commonSituations":"Typo'd or partially-typed job names; token scoped to namespace A while job lives in namespace B; job deleted by CI right before inspection; NOMAD_NAMESPACE mismatch.","solutions":["Check the wrapped cause: 404 = wrong ID/deleted job, 403 = permissions, transport = connectivity.","Run `nomad job status` with no args (or `nomad status`) to list jobs and confirm the exact ID.","Pass -namespace or set NOMAD_NAMESPACE to match where the job actually lives.","Inspect the ACL token (`nomad acl token info`) and ensure it has read-job in the target namespace.","Retry if the cause is transient (the job may have been mid-purge)."],"exampleFix":"// before: job is in another namespace\nnomad job status webapp\n// after\nnomad job status -namespace prod webapp","handlingStrategy":"try-catch","validationCode":"// resolve and confirm the exact ID first\nnomad job status -namespace \"$NS\" \"$EXACT_JOB_ID\" >/dev/null 2>&1 || echo \"job $EXACT_JOB_ID not found in $NS\"","typeGuard":null,"tryCatchPattern":"job, err := JobByPrefix(client, ns, prefix)\nif err != nil && strings.Contains(err.Error(), \"Error querying job\") {\n    var notFound bool\n    if strings.Contains(err.Error(), \"404\") || strings.Contains(err.Error(), \"not found\") { notFound = true }\n    // handle notFound distinctly from auth/network errors\n}","preventionTips":["Always pass the full exact job ID in scripts instead of prefixes.","Match the token's namespaces with the job's namespace.","Confirm jobs exist before inspecting in CI pipelines.","Keep NOMAD_NAMESPACE consistent across commands."],"tags":["nomad-cli","job-lookup","api-error","acl"],"backgroundTag":"resource-not-found","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"}