{"record":{"id":"d17f0bd8ea7ed172","repo":"hashicorp/nomad","slug":"failed-to-create-job-diff-v","errorCode":null,"errorMessage":"failed to create job diff: %v","messagePattern":"failed to create job diff: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/job_endpoint.go","lineNumber":1332,"sourceCode":"\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}\n\n\t\t\t\t\t\td, err := old.Diff(new, true)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"failed to create job diff: %v\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treply.Diffs = append(reply.Diffs, d)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Use the last index that affected the nodes table\n\t\t\t\tindex, err := state.Index(\"job_version\")\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\treply.Index = index\n\t\t\t}\n\n\t\t\t// Set the query response\n\t\t\tj.srv.setQueryMeta(&reply.QueryMeta)\n\t\t\treturn nil\n\t\t}}\n\treturn j.srv.blockingRPC(&opts)","sourceCodeStart":1314,"sourceCodeEnd":1350,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/job_endpoint.go#L1314-L1350","documentation":"During a job plan/diff operation, structs.Job.Diff(old, new, true) failed while building the JobDiff for the reply, and the endpoint wraps the internal error as 'failed to create job diff'. Diff can fail when the underlying job structs cannot be compared safely (e.g. malformed multiregion/update blocks), so this indicates corrupt or unexpected job data rather than a missing resource.","triggerScenarios":"Plan/Scale request with Diffs enabled where old.Diff(new, true) returns a non-nil error inside the diff loop at nomad/job_endpoint.go:1332.","commonSituations":"Submitting hand-crafted or API-generated job JSON with invalid nested blocks; state-store data from an older Nomad version lacking fields newer Diff logic expects; upgrades where persisted versions predate a schema change.","solutions":["Read the wrapped %v error to find which job field failed comparison.","Validate the job spec with 'nomad job validate' before submitting.","Re-submit/normalize the job so both versions use the current schema.","Upgrade Nomad if the error appears only on jobs persisted by an older version; if reproducible, file a bug with the wrapped error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if _, _, err := client.Jobs().Validate(validateJob, nil); err != nil {\n    return fmt.Errorf(\"job spec invalid before diff/plan: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"plan, _, err := client.Jobs().Scale(...)\nif err != nil && strings.Contains(err.Error(), \"failed to create job diff\") {\n    return fmt.Errorf(\"diff failed (%v); retry with Diffs disabled or validate the job spec\", err)\n}","preventionTips":["Always validate job specs with the validate API before plan/diff requests.","Avoid hand-crafting job JSON; generate from jobspec parsing.","Keep server and persisted jobs on the same Nomad version to avoid schema drift."],"tags":["nomad","job-diff","serialization"],"backgroundTag":"job-diff-failed","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"}