{"record":{"id":"eb75c06151257c03","repo":"hashicorp/nomad","slug":"s-d-job-does-not-exist","errorCode":null,"errorMessage":"%s %d: job does not exist","messagePattern":"(.+?) (.+?): job does not exist","errorType":"validation","errorClass":"RegisterEnforceIndexErrPrefix","httpStatus":null,"severity":"error","filePath":"nomad/structs/job.go","lineNumber":317,"sourceCode":"\t\t\t\tbreak // to next TaskGroup\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}\n\n// EnforceIndex checks the `EnforceIndex` logic: if the job exists (not `nil`)\n// it must match the `index` argument and if `index == 0` the job must be `nil`.\nfunc (j *Job) EnforceIndex(index uint64) error {\n\tif j != nil {\n\t\tif index == 0 {\n\t\t\treturn fmt.Errorf(\"%s 0: job already exists\", RegisterEnforceIndexErrPrefix)\n\t\t} else if index != j.JobModifyIndex {\n\t\t\treturn fmt.Errorf(\"%s %d: job exists with conflicting job modify index: %d\",\n\t\t\t\tRegisterEnforceIndexErrPrefix, index, j.JobModifyIndex)\n\t\t}\n\t} else if index != 0 {\n\t\treturn fmt.Errorf(\"%s %d: job does not exist\", RegisterEnforceIndexErrPrefix, index)\n\t}\n\treturn nil\n}\n","sourceCodeStart":299,"sourceCodeEnd":321,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/job.go#L299-L321","documentation":"Job.EnforceIndex compare-and-set check: when the job does NOT exist in state but the caller requested a non-zero index, registration fails because a non-zero index asserts 'job exists with this modify index'. Prefixed with RegisterEnforceIndexErrPrefix.","triggerScenarios":"Job register with EnforceIndex=true and EnforceIndex > 0 for a job ID/namespace that has never been created (or was purged).","commonSituations":"Update-only deploy script run before the job was ever created; job purged or GC'd between read and write; wrong namespace in the register request.","solutions":["Register once with EnforceIndex=0 (create-only) or EnforceIndex disabled to create the job","Verify the namespace and job ID match the intended existing job","Make deployment scripts handle both create and update cases"],"exampleFix":"// before\nEnforceIndex: true, JobModifyIndex: 7 // update-only, job absent\n// after\nEnforceIndex: true, JobModifyIndex: 0 // create-only path","handlingStrategy":"validation","validationCode":"_, _, err := client.Jobs().Info(jobID)\njobExists := err == nil\nif !jobExists && opts.JobModifyIndex > 0 {\n  return errors.New(\"job does not exist; cannot EnforceIndex with nonzero value\")\n}","typeGuard":null,"tryCatchPattern":"_, _, err := client.Jobs().Register(job, &api.RegisterOptions{EnforceIndex: true, JobModifyIndex: idx})\nif err != nil && strings.Contains(err.Error(), \"job does not exist\") {\n  // register with JobModifyIndex 0 to create\n}","preventionTips":["Check job existence before issuing an update-only register","Make create/update flows explicit in CI scripts","Confirm namespace and job ID spelling"],"tags":["nomad","job-register","enforce-index","cas"],"backgroundTag":"enforce-index-mismatch","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}