{"record":{"id":"0fa3b182309c91e8","repo":"hashicorp/nomad","slug":"version-d-not-found","errorCode":null,"errorMessage":"version %d not found","messagePattern":"version (.+?) not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/job_endpoint.go","lineNumber":1310,"sourceCode":"\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}\n\t\t\t\t}\n\t\t\t\treply.Index = maxModifyIndex\n\n\t\t\t\tif compareSpecificVersion && compareVersion == nil {\n\t\t\t\t\tif args.DiffTagName != \"\" {\n\t\t\t\t\t\treturn fmt.Errorf(\"tag %q not found\", args.DiffTagName)\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"version %d not found\", *args.DiffVersion)\n\t\t\t\t}\n\n\t\t\t\t// Compute the diffs\n\n\t\t\t\tif args.Diffs {\n\t\t\t\t\tfor i := range out {\n\t\t\t\t\t\tvar old, new *structs.Job\n\t\t\t\t\t\tnew = out[i]\n\n\t\t\t\t\t\tif compareSpecificVersion {\n\t\t\t\t\t\t\told = compareVersion\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif i == len(out)-1 {\n\t\t\t\t\t\t\t\t// Skip the last version if not comparing to a specific version\n\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\told = out[i+1]\n\t\t\t\t\t\t}","sourceCodeStart":1292,"sourceCodeEnd":1328,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/job_endpoint.go#L1292-L1328","documentation":"A diff/scale request specified args.DiffVersion, but after the state lookup that version does not exist for the job: compareVersion remains nil and DiffTagName is empty, so this message reports the missing version number. Nomad needs the concrete JobVersion to compute the diff and refuses the request.","triggerScenarios":"Calling Job.Scale (or plan with diff) with DiffVersion = N where job 'my-job' in the namespace has fewer than N+1 registered versions, e.g. version 5 requested against a job with only 3 versions, hitting nomad/job_endpoint.go:1310.","commonSituations":"Hardcoded version index after the job was re-registered many times or purged; off-by-one in tooling that assumed 1-based versioning (versions are 0-based); referencing a version of an old job with the same ID after deregistration and recreation.","solutions":["Fetch the job's current versions and pass an existing 0-based version number in DiffVersion.","Use DiffTagName or omit the diff fields if you just want the latest version compared.","Confirm the job ID/namespace; the version likely belongs to a different job.","Re-submit the job to create more versions if the history was reset."],"exampleFix":"// before\ndiffReq.DiffVersion = int64ToPtr(7) // job only has versions 0..3\n// after\njob, _ := client.Jobs().Info(\"my-job\", nil)\ndiffReq.DiffVersion = int64ToPtr(*job.Version) // a known-good existing version","handlingStrategy":"validation","validationCode":"versions, _, err := client.Jobs().Versions(jobID, false, nil)\nif err != nil { return err }\nif version < 0 || version >= int64(len(versions)) {\n    return fmt.Errorf(\"version %d not found for %s (have %d versions, 0-based)\", version, jobID, len(versions))\n}","typeGuard":"func versionExists(num int64, versions []*api.JobVersion) bool {\n    return num >= 0 && int(num) < len(versions)\n}","tryCatchPattern":null,"preventionTips":["Remember job versions are 0-based; never add 1 when indexing.","Fetch the version list dynamically instead of hardcoding indices.","After job deregistration/recreation, version history resets — re-resolve."],"tags":["nomad","job-versioning","version-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"}