{"record":{"id":"1fb247ad36ff3b53","repo":"hashicorp/nomad","slug":"run-for-v-not-a-valid-duration-v","errorCode":null,"errorMessage":"run_for %v not a valid duration: %v","messagePattern":"run_for (.+?) not a valid duration: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/mock/driver.go","lineNumber":412,"sourceCode":"\t\ttaskConfig:      handle.Config,\n\t\tcommand:         taskState.Command,\n\t\texecCommand:     taskState.ExecCommand,\n\t\tprocState:       drivers.TaskStateRunning,\n\t\tstartedAt:       taskState.StartedAt,\n\t\tkill:            killCancel,\n\t\tkillCh:          killCtx.Done(),\n\t\tRecovered:       true,\n\t}\n\n\td.tasks.Set(handle.Config.ID, h)\n\tgo h.run()\n\treturn nil\n}\n\nfunc (c *Command) parseDurations() error {\n\tvar err error\n\tif c.runForDuration, err = parseDuration(c.RunFor); err != nil {\n\t\treturn fmt.Errorf(\"run_for %v not a valid duration: %v\", c.RunFor, err)\n\t}\n\n\tif c.stdoutRepeatDuration, err = parseDuration(c.StdoutRepeatDur); err != nil {\n\t\treturn fmt.Errorf(\"stdout_repeat_duration %v not a valid duration: %v\", c.stdoutRepeatDuration, err)\n\t}\n\n\tif c.stderrRepeatDuration, err = parseDuration(c.StderrRepeatDur); err != nil {\n\t\treturn fmt.Errorf(\"stderr_repeat_duration %v not a valid duration: %v\", c.stderrRepeatDuration, err)\n\t}\n\n\treturn nil\n}\n\nfunc parseDriverConfig(cfg *drivers.TaskConfig) (*TaskConfig, error) {\n\tvar driverConfig TaskConfig\n\tif err := cfg.DecodeDriverConfig(&driverConfig); err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/mock/driver.go#L394-L430","documentation":"The mock driver's Command config accepts human-friendly duration strings (e.g. \"5s\", \"1m\"). parseDurations converts RunFor via parseDuration, and any value time.ParseDuration cannot parse produces this wrapped error. It surfaces during task recovery (RecoverTask) or when parsing driver config in StartTask.","triggerScenarios":"A mock task's command config sets run_for to something like \"10\", \"forever\", \"5sec\", or an empty string; parseDuration (which appends 's' for bare numbers per its own rules) still fails to parse it.","commonSituations":"Typo in job file (\"run_for = \"5 mintues\"\"); passing a bare number with a unit the helper doesn't handle; config values interpolated from environment variables that came in empty or malformed; older persisted state with a now-invalid format.","solutions":["Fix run_for in the task/driver config to a valid duration string like \"30s\", \"5m\", or \"1h\".","Check the inner %v (from time.ParseDuration) for exactly which part failed to parse.","If the value comes from interpolation, verify the variable is set and correctly formatted before submit.","For recovered tasks with stale state, resubmit the job with corrected config instead of recovering."],"exampleFix":"// before\nc.RunFor = \"10 minutes\"\n// after\nc.RunFor = \"10m\"","handlingStrategy":"validation","validationCode":"if _, err := time.ParseDuration(c.RunFor); err != nil {\n    return fmt.Errorf(\"run_for must be a Go duration like 30s, got %q\", c.RunFor)\n}","typeGuard":"func validDuration(s string) bool { _, err := time.ParseDuration(s); return err == nil }","tryCatchPattern":"if err := cmd.parseDurations(); err != nil {\n    // err names the field and bad value; fix config and resubmit\n    return fmt.Errorf(\"invalid mock command config: %w\", err)\n}","preventionTips":["Always include a unit suffix (s, m, h) in duration config values.","Lint/validate job specs before submission to catch malformed durations.","Check interpolated variables resolve to non-empty, well-formed strings.","Remember bare numbers get 's' appended by the mock helper — \"5\" means 5s, not 5 minutes."],"tags":["nomad","mock-driver","duration-parsing","config-validation"],"backgroundTag":"invalid-duration-format","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"}