{"record":{"id":"2a9beb811511dea1","repo":"hashicorp/nomad","slug":"failed-to-parse-value-of-q-v-as-a-bool-v","errorCode":null,"errorMessage":"Failed to parse value of %q (%v) as a bool: %v","messagePattern":"Failed to parse value of %q \\((.+?)\\) as a bool: (.+?)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"command/agent/http.go","lineNumber":1048,"sourceCode":"\t} else if *n == \"\" {\n\t\t*n = structs.DefaultNamespace\n\t}\n}\n\n// parseIdempotencyToken is used to parse the ?idempotency_token parameter\nfunc parseIdempotencyToken(req *http.Request, n *string) {\n\tif idempotencyToken := req.URL.Query().Get(\"idempotency_token\"); idempotencyToken != \"\" {\n\t\t*n = idempotencyToken\n\t}\n}\n\n// parseBool parses a query parameter to a boolean or returns (nil, nil) if the\n// parameter is not present.\nfunc 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","sourceCodeStart":1030,"sourceCodeEnd":1066,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/http.go#L1030-L1066","documentation":"This error is returned by the Nomad agent's parseBool helper (command/agent/http.go:1048) when a boolean query parameter on an HTTP API request cannot be parsed by strconv.ParseBool. It wraps the underlying strconv error so the caller knows which query field had the bad value and what the raw string was. It is a request-validation failure, not a server fault; the request is rejected (HTTP 400) before reaching the handler logic.","triggerScenarios":"Any HTTP GET/POST to a Nomad agent HTTP endpoint that reads a boolean query parameter via parseBool (e.g. ?stale=..., ?namespace-like flags) where the parameter value is a non-empty string that is not one of: 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Example: GET /v1/jobs?stale=yes or ?node_include=on.","commonSituations":"Hand-built curl commands using 'yes'/'no', 'on'/'off' or empty-but-present values like '?stale='; shell scripts interpolating unset variables into the URL (e.g. ?stale=$FLAG where FLAG is garbage); non-English tooling producing 'wahr/falsch' style values; API clients typing the parameter as a free-form string instead of bool.","solutions":["Change the query parameter value to a Go-accepted boolean literal: true/false (also 1/0, t/f, T/F, TRUE/FALSE, True/False are accepted).","Remove the query parameter entirely if you do not need it; absent parameters are treated as nil and do not error.","Check the field name and raw value echoed in the error message (%q shows the field, %v the value) to spot typos or unexpanded shell variables.","If you own client code, cast/serialize the value to a proper boolean before appending it to the URL."],"exampleFix":"// before\ncurl 'http://127.0.0.1:4646/v1/jobs?stale=yes'\n// after\ncurl 'http://127.0.0.1:4646/v1/jobs?stale=true'","handlingStrategy":"validation","validationCode":"// Validate a boolean query param before calling the Nomad API\nfunc validBoolParam(v string) bool {\n    _, err := strconv.ParseBool(v)\n    return err == nil\n}\n// if !validBoolParam(stale) { fix before requesting }\n","typeGuard":"func isGoBool(s string) bool {\n    switch s {\n    case \"1\", \"t\", \"T\", \"true\", \"TRUE\", \"True\", \"0\", \"f\", \"F\", \"false\", \"FALSE\", \"False\":\n        return true\n    }\n    return false\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 bool\n    return fmt.Errorf(\"bad query param: %s\", body)\n}","preventionTips":["Always serialize booleans with strconv.FormatBool or the client library's native bool type.","Never write 'yes'/'no'/'on'/'off' into boolean query params.","Omit boolean params entirely rather than passing empty strings.","Keep a small helper that validates query params against Go's ParseBool before sending."],"tags":["http","query-parameter","parsing","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-08T05:18:18.240Z"}