{"record":{"id":"05f41f8cf393bbec","repo":"hashicorp/nomad","slug":"prefix-q-matched-multiple-jobs-n-n-s-s","errorCode":null,"errorMessage":"Prefix %q matched multiple jobs\\n\\n%s%s","messagePattern":"Prefix %q matched multiple jobs\\\\n\\\\n(.+?)(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/meta.go","lineNumber":402,"sourceCode":"\t\t\t\tfiltered = append(filtered, j)\n\t\t\t}\n\t\t}\n\t\tjobs = filtered\n\t\ttruncated = false // the unfiltered prefix list is complete\n\t}\n\n\tif len(jobs) == 0 {\n\t\treturn \"\", \"\", &NoJobWithPrefixError{Prefix: prefix}\n\t}\n\tif len(jobs) > 1 {\n\t\texactMatch := prefix == jobs[0].ID\n\t\tmatchInMultipleNamespaces := m.allNamespaces() && jobs[0].ID == jobs[1].ID\n\t\ttruncatedMsg := \"\"\n\t\tif truncated {\n\t\t\ttruncatedMsg = \"\\n(results may be truncated)\"\n\t\t}\n\t\tif !exactMatch || matchInMultipleNamespaces {\n\t\t\treturn \"\", \"\", fmt.Errorf(\n\t\t\t\t\"Prefix %q matched multiple jobs\\n\\n%s%s\",\n\t\t\t\tprefix,\n\t\t\t\tcreateStatusListOutput(jobs, m.allNamespaces()),\n\t\t\t\ttruncatedMsg,\n\t\t\t)\n\t\t}\n\t}\n\n\treturn jobs[0].ID, jobs[0].JobSummary.Namespace, nil\n}\n\ntype usageOptsFlags uint8\n\nconst (\n\tusageOptsDefault     usageOptsFlags = 0\n\tusageOptsNoNamespace                = 1 << iota\n)\n","sourceCodeStart":384,"sourceCodeEnd":420,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/meta.go#L384-L420","documentation":"Returned by jobIDByPrefix when a job prefix is ambiguous: either there is no exact ID match among the candidates, or the top two matches share the same job ID in different namespaces. The CLI refuses to guess and prints the full candidate list (plus a truncation hint if results were cut off) so the user can disambiguate.","triggerScenarios":"A prefix like `nomad job status we` that matches multiple jobs (e.g. web, webapp) with no exact match, or one job ID existing in several namespaces while -all-namespaces/-namespace wildcard is in effect, making the match ambiguous.","commonSituations":"Short prefixes in namespaces with similarly-named jobs; identical job names deployed in dev and prod namespaces queried with all-namespaces mode; overly generic prefixes like 'api' or 'job'.","solutions":["Use a longer prefix so exactly one job matches, e.g. `nomad job status webap`.","Specify the job's full ID exactly — an exact ID match bypasses the ambiguity error.","Pass -namespace <ns> to narrow the search to one namespace.","Read the candidate list printed in the error and pick the right ID.","If the list was truncated, add namespace filters to reduce result size."],"exampleFix":"// before: ambiguous\nnomad job status web\n// after: exact ID and namespace\nnomad job status -namespace prod webapp","handlingStrategy":"validation","validationCode":"// resolve ambiguity before invoking: count matches yourself\nmatches=$(nomad job status -namespace \"$NS\" | grep -c \"^$PREFIX\")\n[ \"$matches\" -le 1 ] || { echo \"prefix '$PREFIX' is ambiguous in $NS\"; exit 1; }","typeGuard":null,"tryCatchPattern":"id, ns, err := JobIDByPrefix(client, ns, prefix, filter)\nif err != nil && strings.Contains(err.Error(), \"matched multiple jobs\") {\n    // print err (it embeds the candidate list) and prompt user to refine\n    return fmt.Errorf(\"refine prefix: %w\", err)\n}","preventionTips":["Use full job IDs in scripts, prefixes only interactively.","Always pass -namespace in multi-namespace clusters.","Avoid very short/generic prefixes like 'web' or 'api'.","Keep job naming conventions distinct per namespace."],"tags":["nomad-cli","ambiguity","prefix-lookup","user-input"],"backgroundTag":"ambiguous-prefix-match","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"}