hashicorp/nomad · error
Failed to parse value of %q (%v) as a int: %v
Error message
Failed to parse value of %q (%v) as a int: %v
What it means
This error is returned by the Nomad agent's parseInt helper (command/agent/http.go:1062) when an integer query parameter cannot be parsed by strconv.Atoi. The error names the failing query field, the offending raw value, and the underlying strconv error. The HTTP request is rejected as malformed (400); it does not indicate a server problem.
Source
Thrown at command/agent/http.go:1062
func parseBool(req *http.Request, field string) (*bool, error) {
if str := req.URL.Query().Get(field); str != "" {
param, err := strconv.ParseBool(str)
if err != nil {
return nil, fmt.Errorf("Failed to parse value of %q (%v) as a bool: %v", field, str, err)
}
return ¶m, nil
}
return nil, nil
}
// parseInt parses a query parameter to a int or returns (nil, nil) if the
// parameter is not present.
func parseInt(req *http.Request, field string) (*int, error) {
if str := req.URL.Query().Get(field); str != "" {
param, err := strconv.Atoi(str)
if err != nil {
return nil, fmt.Errorf("Failed to parse value of %q (%v) as a int: %v", field, str, err)
}
return ¶m, nil
}
return nil, nil
}
// parseToken is used to get an authentication token from the request
func (s *HTTPServer) parseToken(req *http.Request, token *string) {
if other := req.Header.Get("X-Nomad-Token"); other != "" {
*token = strings.TrimSpace(other)
return
}
if other := req.Header.Get("Authorization"); other != "" {
// HTTP Authorization headers are in the format: <Scheme>[SPACE]<Value>
// Ref. https://tools.ietf.org/html/rfc7236#section-3
parts := strings.Split(other, " ")View on GitHub (pinned to 482b49bf1a)
Solutions
- Send a plain base-10 integer with no quotes, units, or decimals, e.g. ?eval_priority=50.
- Keep the value within the signed int range for the platform (typically 64-bit: ±9.2e18).
- Remove the parameter if a default is acceptable; absent params return nil and do not error.
- Read the %q/%v fields in the error message to identify which param and which raw value failed, then fix the client code.
Example fix
// before
url := fmt.Sprintf("/v1/job/%s?eval_priority=%s", jobID, "high")
// after
url := fmt.Sprintf("/v1/job/%s?eval_priority=%d", jobID, 80) Defensive patterns
Strategy: validation
Validate before calling
// Validate an integer query param before calling the Nomad API
if _, err := strconv.Atoi(val); err != nil {
return fmt.Errorf("query param %s must be an integer, got %q", name, val)
} Type guard
func isInt(s string) bool {
_, err := strconv.Atoi(s)
return err == nil
} Try / catch
resp, err := http.Get(url)
if err != nil { return err }
if resp.StatusCode == 400 {
body, _ := io.ReadAll(resp.Body)
// match on: Failed to parse value of ... as a int
return fmt.Errorf("non-integer query param: %s", body)
} Prevention
- Use %d formatting, never %s, for numeric query params.
- Avoid locale-formatted numbers (thousands separators, decimals).
- Check values fit in a signed int (±9.2e18 on 64-bit).
- Omit the parameter when the default suffices.
When it happens
Trigger: Any Nomad HTTP API request passing an integer query param via parseInt (e.g. ?eval_priority=..., ?next_token-like numeric params) with a non-numeric or out-of-int-range value, e.g. ?eval_priority=high, ?count=1.5, or ?eval_priority=99999999999999999999.
Common situations: Passing a named enum string where a number is expected (priority='high' instead of 80); decimal separators or thousands separators ('1,000'); values exceeding the platform int size; scripts interpolating empty or garbage variables into the query string.
Understand the failure class
Background: "Invalid query parameter" / "Failed to parse value of ...": fixing bad query string parameters across APIs — this error's family across 36 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse value of %q (%v) as a bool: %v
- Failed to parse value of %q (%v) as a uint64: %v
- tty value is not a boolean: %v
- Failed to parse value of %q (%v) as a bool: %v
- Failed to parse value of %qq (%v) as a bool: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/21531045df1d5ada.
Report an issue: GitHub.