{"record":{"id":"21531045df1d5ada","repo":"hashicorp/nomad","slug":"failed-to-parse-value-of-q-v-as-a-int-v","errorCode":null,"errorMessage":"Failed to parse value of %q (%v) as a int: %v","messagePattern":"Failed to parse value of %q \\((.+?)\\) as a int: (.+?)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"command/agent/http.go","lineNumber":1062,"sourceCode":"func parseBool(req *http.Request, field string) (*bool, error) {\n\tif str := req.URL.Query().Get(field); str != \"\" {\n\t\tparam, err := strconv.ParseBool(str)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Failed to parse value of %q (%v) as a bool: %v\", field, str, err)\n\t\t}\n\t\treturn &param, nil\n\t}\n\n\treturn nil, nil\n}\n\n// parseInt parses a query parameter to a int or returns (nil, nil) if the\n// parameter is not present.\nfunc parseInt(req *http.Request, field string) (*int, error) {\n\tif str := req.URL.Query().Get(field); str != \"\" {\n\t\tparam, err := strconv.Atoi(str)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Failed to parse value of %q (%v) as a int: %v\", field, str, err)\n\t\t}\n\t\treturn &param, nil\n\t}\n\treturn nil, nil\n}\n\n// parseToken is used to get an authentication token from the request\nfunc (s *HTTPServer) parseToken(req *http.Request, token *string) {\n\n\tif other := req.Header.Get(\"X-Nomad-Token\"); other != \"\" {\n\t\t*token = strings.TrimSpace(other)\n\t\treturn\n\t}\n\n\tif other := req.Header.Get(\"Authorization\"); other != \"\" {\n\t\t// HTTP Authorization headers are in the format: <Scheme>[SPACE]<Value>\n\t\t// Ref. https://tools.ietf.org/html/rfc7236#section-3\n\t\tparts := strings.Split(other, \" \")","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/http.go#L1044-L1080","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nurl := fmt.Sprintf(\"/v1/job/%s?eval_priority=%s\", jobID, \"high\")\n// after\nurl := fmt.Sprintf(\"/v1/job/%s?eval_priority=%d\", jobID, 80)","handlingStrategy":"validation","validationCode":"// Validate an integer query param before calling the Nomad API\nif _, err := strconv.Atoi(val); err != nil {\n    return fmt.Errorf(\"query param %s must be an integer, got %q\", name, val)\n}","typeGuard":"func isInt(s string) bool {\n    _, err := strconv.Atoi(s)\n    return err == nil\n}","tryCatchPattern":"resp, err := http.Get(url)\nif err != nil { return err }\nif resp.StatusCode == 400 {\n    body, _ := io.ReadAll(resp.Body)\n    // match on: Failed to parse value of ... as a int\n    return fmt.Errorf(\"non-integer query param: %s\", body)\n}","preventionTips":["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."],"tags":["http","query-parameter","parsing","integer","nomad"],"backgroundTag":"invalid-query-parameter","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"}