{"record":{"id":"8627062398fca105","repo":"hashicorp/nomad","slug":"not-a-valid-task-schedule-state","errorCode":null,"errorMessage":"not a valid task schedule state","messagePattern":"not a valid task schedule state","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/node.go","lineNumber":442,"sourceCode":"\tScheduleState TaskScheduleState\n}\n\nfunc (r *ScheduleStateApplyRequest) Validate() error {\n\tif r.AllocID == \"\" {\n\t\treturn errors.New(\"alloc id must be set\")\n\t}\n\n\tif r.TaskName == \"\" {\n\t\treturn errors.New(\"task name must be set\")\n\t}\n\n\tswitch r.ScheduleState {\n\tcase TaskScheduleStateRun:\n\tcase TaskScheduleStateForceRun:\n\tcase TaskScheduleStateSchedPause:\n\tcase TaskScheduleStateForcePause:\n\tdefault:\n\t\treturn errors.New(\"not a valid task schedule state\")\n\t}\n\n\treturn nil\n}\n\n// ScheduleStateReadRequest is used to read the current pause state of a specific\n// task running on a client.\ntype ScheduleStateReadRequest struct {\n\tQueryOptions // Client RPCs must use QueryOptions\n\n\t// NodeID is the node being targeted by this request (or the node receiving\n\t// this request if NodeID is empty).\n\tNodeID string\n\n\t// AllocID is the allocation being targeted by this request.\n\tAllocID string\n\n\t// TaskName is the name of the task being targeted by this request.","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/node.go#L424-L460","documentation":"ScheduleStateApplyRequest.Validate accepts only TaskScheduleStateRun, ForceRun, SchedPause, and ForcePause. Any other value — including the zero value if it is not one of these — returns 'not a valid task schedule state', protecting the state machine from invalid transitions.","triggerScenarios":"Submitting a ScheduleStateApplyRequest with ScheduleState set to an unknown/zero integer not in {Run, ForceRun, SchedPause, ForcePause}; the switch default at node.go:442.","commonSituations":"Casting raw ints from external tooling into TaskScheduleState; API clients sending string states that decode to an unmapped numeric value; versions where a new state was added client-side but not on the server.","solutions":["Use the exported TaskScheduleState constants instead of raw integers","Map API string inputs to valid constants with an explicit switch/mapping table","Check client/server version parity if using a newly added state value","Default to an explicit valid state (e.g. TaskScheduleStateRun) rather than the zero value"],"exampleFix":"// before\nreq := &structs.ScheduleStateApplyRequest{\n  AllocID: allocID,\n  TaskName: \"redis\",\n  ScheduleState: structs.TaskScheduleState(7), // invalid\n}\n\n// after\nreq := &structs.ScheduleStateApplyRequest{\n  AllocID: allocID,\n  TaskName: \"redis\",\n  ScheduleState: structs.TaskScheduleStateSchedPause,\n}","handlingStrategy":"type-guard","validationCode":"switch st {\ncase structs.TaskScheduleStateRun, structs.TaskScheduleStateForceRun,\n\tstructs.TaskScheduleStateSchedPause, structs.TaskScheduleStateForcePause:\n\t// ok\ndefault:\n\treturn fmt.Errorf(\"invalid schedule state %d\", st)\n}","typeGuard":"func validTaskScheduleState(s structs.TaskScheduleState) bool {\n\tswitch s {\n\tcase structs.TaskScheduleStateRun,\n\t\tstructs.TaskScheduleStateForceRun,\n\t\tstructs.TaskScheduleStateSchedPause,\n\t\tstructs.TaskScheduleStateForcePause:\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":null,"preventionTips":["Use exported constants, never raw ints","Explicitly map string inputs to constants","Verify state enum parity across Nomad versions"],"tags":["nomad","task-scheduling","enum","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"}