{"record":{"id":"c68bca82cc4c7f00","repo":"hashicorp/nomad","slug":"tag-q-not-found","errorCode":null,"errorMessage":"tag %q not found","messagePattern":"tag %q not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/job_endpoint.go","lineNumber":1284,"sourceCode":"\t\t\t}\n\n\t\t\t// Setup the output\n\t\t\treply.Versions = out\n\t\t\tif len(out) != 0 {\n\n\t\t\t\tvar compareVersionNumber uint64\n\t\t\t\tvar compareVersion *structs.Job\n\t\t\t\tvar compareSpecificVersion bool\n\n\t\t\t\tif args.Diffs {\n\t\t\t\t\tif args.DiffTagName != \"\" {\n\t\t\t\t\t\tcompareSpecificVersion = true\n\t\t\t\t\t\tcompareVersion, err = state.JobVersionByTagName(ws, args.RequestNamespace(), args.JobID, args.DiffTagName)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error looking up job version by tag: %v\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif compareVersion == nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"tag %q not found\", args.DiffTagName)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcompareVersionNumber = compareVersion.Version\n\t\t\t\t\t} else if args.DiffVersion != nil {\n\t\t\t\t\t\tcompareSpecificVersion = true\n\t\t\t\t\t\tcompareVersionNumber = *args.DiffVersion\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Note: a previous assumption here was that the 0th job was the latest, and that we don't modify \"old\" versions.\n\t\t\t\t// Adding version tags breaks this assumption (you can tag an old version, which should unblock /versions queries) so we now look for the highest ModifyIndex.\n\t\t\t\tvar maxModifyIndex uint64\n\t\t\t\tfor _, job := range out {\n\t\t\t\t\tif job.ModifyIndex > maxModifyIndex {\n\t\t\t\t\t\tmaxModifyIndex = job.ModifyIndex\n\t\t\t\t\t}\n\t\t\t\t\tif compareSpecificVersion && job.Version == compareVersionNumber {\n\t\t\t\t\t\tcompareVersion = job\n\t\t\t\t\t}","sourceCodeStart":1266,"sourceCodeEnd":1302,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/job_endpoint.go#L1266-L1302","documentation":"Job.Scale or a diff request with DiffTagName set looked up a job version by tag name via state.JobVersionByTagName and got a nil result. The tag exists nowhere in the state store for that job/namespace, so Nomad cannot resolve it to a version number and aborts the request. This is a pre-flight existence check for the user-supplied tag reference.","triggerScenarios":"Calling the job scale or plan/diff RPC with args.DiffTagName set to a tag that does not exist for args.JobID in args.RequestNamespace(). state.JobVersionByTagName returns (nil, nil) when no version carries that tag, hitting the `compareVersion == nil` branch at nomad/job_endpoint.go:1284.","commonSituations":"Typo in the tag name; tag was deleted when a job was stopped and purged; tag attached to a job in a different namespace; tooling assumes a tag was promoted when the promotion failed; querying before the tagged job version was ever registered.","solutions":["List the job's versions/tags (nomad job status -all-allocs / job versions API) and use an exact existing tag name.","Verify you are querying the correct namespace; tags are scoped per namespace and job ID.","Check for typos or case differences in DiffTagName.","If the tag should exist, confirm the job was not purged/paused and re-tag the desired version."],"exampleFix":"// before\nargs.DiffTagName = \"prod\"\n// after\ntags, _ := client.Jobs().Versions(\"my-job\", false, nil) // inspect Tags per version\nif !tagExists(tags, \"prod\") {\n    args.DiffTagName = \"\" // fall back to DiffVersion or fix the name\n}","handlingStrategy":"validation","validationCode":"versions, _, err := client.Jobs().Versions(jobID, true, nil)\nif err != nil { return err }\nfound := false\nfor _, v := range versions {\n    for _, t := range v.Tags { if t == wantedTag { found = true } }\n}\nif !found { return fmt.Errorf(\"tag %q does not exist for job %s\", wantedTag, jobID) }","typeGuard":"func tagExists(versions []*api.JobVersions, tag string) bool {\n    for _, v := range versions { for _, t := range v.Tags { if t == tag { return true } } }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Verify tag existence against job versions before any diff/scale call that uses DiffTagName.","Scope tags per namespace and job ID; always pass the same namespace you tagged in.","Treat tags as mutable — re-check after job purges or re-registrations."],"tags":["nomad","job-versioning","tag-not-found"],"backgroundTag":"referenced-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"}