{"record":{"id":"cd227de586758942","repo":"hashicorp/nomad","slug":"invalid-answer-q","errorCode":null,"errorMessage":"Invalid answer %q","messagePattern":"Invalid answer %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/job_restart.go","lineNumber":782,"sourceCode":"\treturn c.askQuestion(\n\t\tfmt.Sprintf(\"%s [%s]\", question, options),\n\t\tfalse,\n\t\tfunc(answer string) (bool, error) {\n\t\t\tswitch strings.ToLower(answer) {\n\t\t\tcase \"\":\n\t\t\t\t// Proceed by default only if there is no error.\n\t\t\t\treturn err == nil, nil\n\t\t\tcase \"y\", \"yes\":\n\t\t\t\treturn true, nil\n\t\t\tcase \"n\", \"no\":\n\t\t\t\treturn false, nil\n\t\t\tdefault:\n\t\t\t\tif c.batchWaitAsk {\n\t\t\t\t\t// Check if user passed a time duration and adjust the\n\t\t\t\t\t// command to use that moving forward.\n\t\t\t\t\tbatchWait, err := time.ParseDuration(answer)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn false, fmt.Errorf(\"Invalid answer %q\", answer)\n\t\t\t\t\t}\n\n\t\t\t\t\tc.batchWaitAsk = false\n\t\t\t\t\tc.batchWait = batchWait\n\t\t\t\t\tc.Ui.Output(c.Colorize().Color(fmt.Sprintf(\n\t\t\t\t\t\t\"[bold]==> %s: Proceeding restarts with new wait time of %s[reset]\",\n\t\t\t\t\t\tformatTime(time.Now()),\n\t\t\t\t\t\tc.batchWait,\n\t\t\t\t\t)))\n\t\t\t\t\treturn true, nil\n\t\t\t\t} else {\n\t\t\t\t\treturn false, fmt.Errorf(\"Invalid answer %q\", answer)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n}\n\n// shouldExit blocks and waits for the user for confirmation if they would like","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/job_restart.go#L764-L800","documentation":"When the job restart command asks how long to wait between batch restarts and the user typed a duration string, time.ParseDuration must succeed. If the answer is not a valid Go duration (e.g. '10' without a unit), the command rejects it with Invalid answer %q.","triggerScenarios":"Answering the batch-wait interactive prompt with a string that fails time.ParseDuration, e.g. '10', '10secs', 'abc' instead of '10s'.","commonSituations":"User omits the time unit at the prompt; uses units Go doesn't understand (e.g. 'min' instead of 'm', 'seconds' instead of 's').","solutions":["Re-answer the prompt with a valid duration including a unit, e.g. 30s or 5m","Use units supported by time.ParseDuration: ns, us, ms, s, m, h","Use plain 'y'/'n' answers if you don't want to change the wait time"],"exampleFix":"// before\nanswer: \"30\"          # rejected\n// after\nanswer: \"30s\"        # accepted","handlingStrategy":"validation","validationCode":"_, err := time.ParseDuration(input)\nif err != nil {\n    return fmt.Errorf(\"use a duration like 30s or 5m\")\n}","typeGuard":null,"tryCatchPattern":"// the CLI re-prompts; at call sites wrap:\nif err != nil {\n    ui.Error(fmt.Sprintf(\"%v; expected e.g. 30s\", err))\n    return retryPrompt()\n}","preventionTips":["Always include time units (s/m/h) at interactive prompts","Remember valid units: ns, us, ms, s, m, h"],"tags":["cli","interactive","parsing","duration"],"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"}