hashicorp/nomad · error

version %d not found

Error message

version %d not found

What it means

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.

Source

Thrown at nomad/job_endpoint.go:1310

				// Note: a previous assumption here was that the 0th job was the latest, and that we don't modify "old" versions.
				// 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.
				var maxModifyIndex uint64
				for _, job := range out {
					if job.ModifyIndex > maxModifyIndex {
						maxModifyIndex = job.ModifyIndex
					}
					if compareSpecificVersion && job.Version == compareVersionNumber {
						compareVersion = job
					}
				}
				reply.Index = maxModifyIndex

				if compareSpecificVersion && compareVersion == nil {
					if args.DiffTagName != "" {
						return fmt.Errorf("tag %q not found", args.DiffTagName)
					}
					return fmt.Errorf("version %d not found", *args.DiffVersion)
				}

				// Compute the diffs

				if args.Diffs {
					for i := range out {
						var old, new *structs.Job
						new = out[i]

						if compareSpecificVersion {
							old = compareVersion
						} else {
							if i == len(out)-1 {
								// Skip the last version if not comparing to a specific version
								break
							}
							old = out[i+1]
						}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Fetch the job's current versions and pass an existing 0-based version number in DiffVersion.
  2. Use DiffTagName or omit the diff fields if you just want the latest version compared.
  3. Confirm the job ID/namespace; the version likely belongs to a different job.
  4. Re-submit the job to create more versions if the history was reset.

Example fix

// before
diffReq.DiffVersion = int64ToPtr(7) // job only has versions 0..3
// after
job, _ := client.Jobs().Info("my-job", nil)
diffReq.DiffVersion = int64ToPtr(*job.Version) // a known-good existing version
Defensive patterns

Strategy: validation

Validate before calling

versions, _, err := client.Jobs().Versions(jobID, false, nil)
if err != nil { return err }
if version < 0 || version >= int64(len(versions)) {
    return fmt.Errorf("version %d not found for %s (have %d versions, 0-based)", version, jobID, len(versions))
}

Type guard

func versionExists(num int64, versions []*api.JobVersion) bool {
    return num >= 0 && int(num) < len(versions)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/0fa3b182309c91e8. Report an issue: GitHub.