{"record":{"id":"6c8e15f65cfe7c72","repo":"hashicorp/nomad","slug":"invalid-hook-v","errorCode":null,"errorMessage":"invalid hook: %v","messagePattern":"invalid hook: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":6189,"sourceCode":"\t}\n\tnd := new(TaskLifecycleConfig)\n\t*nd = *d\n\treturn nd\n}\n\nfunc (d *TaskLifecycleConfig) Validate() error {\n\tif d == nil {\n\t\treturn nil\n\t}\n\n\tswitch d.Hook {\n\tcase TaskLifecycleHookPrestart:\n\tcase TaskLifecycleHookPoststart:\n\tcase TaskLifecycleHookPoststop:\n\tcase \"\":\n\t\treturn fmt.Errorf(\"no lifecycle hook provided\")\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid hook: %v\", d.Hook)\n\t}\n\n\treturn nil\n}\n\nvar (\n\t// These default restart policies needs to be in sync with\n\t// Canonicalize in api/tasks.go\n\n\tDefaultServiceJobRestartPolicy = RestartPolicy{\n\t\tDelay:           15 * time.Second,\n\t\tAttempts:        2,\n\t\tInterval:        30 * time.Minute,\n\t\tMode:            RestartPolicyModeFail,\n\t\tRenderTemplates: false,\n\t}\n\tDefaultBatchJobRestartPolicy = RestartPolicy{\n\t\tDelay:           15 * time.Second,","sourceCodeStart":6171,"sourceCodeEnd":6207,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L6171-L6207","documentation":"TaskLifecycleConfig.Validate() accepts only the three known hooks: prestart, poststart, poststop. Any other non-empty `hook` string hits the default branch and produces this error with the invalid value interpolated.","triggerScenarios":"Setting `hook` to a misspelled or unsupported value such as `pre-start`, `PresTart`, `restart`, or `stop` in a task's lifecycle block, then running `nomad job run` or a plan/validate call.","commonSituations":"Typos or wrong casing; confusing Nomad lifecycle hooks with Docker/systemd hook names; following outdated documentation or examples from other schedulers.","solutions":["Use exactly one of `prestart`, `poststart`, or `poststop` (lowercase) for `hook`.","Check `nomad job validate <file>` output — it echoes the invalid value to identify the typo.","Verify the Nomad version supports the intended hook (all three exist in supported versions; there is no 'prerestart')."],"exampleFix":"// before\nlifecycle {\n  hook = \"pre-start\"\n}\n// after\nlifecycle {\n  hook = \"prestart\"\n}","handlingStrategy":"validation","validationCode":"var validHooks = map[string]bool{\"prestart\": true, \"poststart\": true, \"poststop\": true}\nif !validHooks[lc.Hook] {\n\treturn fmt.Errorf(\"invalid hook %q; use prestart|poststart|poststop\", lc.Hook)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Lowercase hook values exactly: prestart, poststart, poststop.","Do not reuse hook names from other ecosystems (Docker, systemd).","Keep a shared constant list of valid hooks in tooling that generates Nomad jobs."],"tags":["nomad","job-spec","lifecycle","validation"],"backgroundTag":"invalid-enum-value","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"}