hashicorp/nomad · error
Invalid answer %q
Error message
Invalid answer %q
What it means
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.
Source
Thrown at command/job_restart.go:782
return c.askQuestion(
fmt.Sprintf("%s [%s]", question, options),
false,
func(answer string) (bool, error) {
switch strings.ToLower(answer) {
case "":
// Proceed by default only if there is no error.
return err == nil, nil
case "y", "yes":
return true, nil
case "n", "no":
return false, nil
default:
if c.batchWaitAsk {
// Check if user passed a time duration and adjust the
// command to use that moving forward.
batchWait, err := time.ParseDuration(answer)
if err != nil {
return false, fmt.Errorf("Invalid answer %q", answer)
}
c.batchWaitAsk = false
c.batchWait = batchWait
c.Ui.Output(c.Colorize().Color(fmt.Sprintf(
"[bold]==> %s: Proceeding restarts with new wait time of %s[reset]",
formatTime(time.Now()),
c.batchWait,
)))
return true, nil
} else {
return false, fmt.Errorf("Invalid answer %q", answer)
}
}
})
}
// shouldExit blocks and waits for the user for confirmation if they would likeView on GitHub (pinned to 482b49bf1a)
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
Example fix
// before answer: "30" # rejected // after answer: "30s" # accepted
Defensive patterns
Strategy: validation
Validate before calling
_, err := time.ParseDuration(input)
if err != nil {
return fmt.Errorf("use a duration like 30s or 5m")
} Try / catch
// the CLI re-prompts; at call sites wrap:
if err != nil {
ui.Error(fmt.Sprintf("%v; expected e.g. 30s", err))
return retryPrompt()
} Prevention
- Always include time units (s/m/h) at interactive prompts
- Remember valid units: ns, us, ms, s, m, h
When it happens
Trigger: Answering the batch-wait interactive prompt with a string that fails time.ParseDuration, e.g. '10', '10secs', 'abc' instead of '10s'.
Common situations: User omits the time unit at the prompt; uses units Go doesn't understand (e.g. 'min' instead of 'm', 'seconds' instead of 's').
Understand the failure class
Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.
Related errors
- error parsing HTTPReadTimeout: %w
- error parsing HTTPMaxSize: %w
- error parsing GCSTimeout: %w
- error parsing GitTimeout: %w
- error parsing HgTimeout: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/cd227de586758942.
Report an issue: GitHub.