{"record":{"id":"a3e6bd52db29abb6","repo":"hashicorp/nomad","slug":"failed-to-parse-value-of-q-v-as-a-bool-v-a3e6bd","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/job_endpoint.go","lineNumber":629,"sourceCode":"\t}\n\tsetIndex(resp, out.Index)\n\treturn out, nil\n}\n\nfunc (s *HTTPServer) jobDelete(resp http.ResponseWriter, req *http.Request, jobID string) (any, error) {\n\n\targs := structs.JobDeregisterRequest{\n\t\tJobID: jobID,\n\t}\n\n\t// Identify the purge query param and parse.\n\tpurgeStr := req.URL.Query().Get(\"purge\")\n\tvar purgeBool bool\n\tif purgeStr != \"\" {\n\t\tvar err error\n\t\tpurgeBool, err = strconv.ParseBool(purgeStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Failed to parse value of %q (%v) as a bool: %v\", \"purge\", purgeStr, err)\n\t\t}\n\t}\n\targs.Purge = purgeBool\n\n\t// Identify the global query param and parse.\n\tglobalStr := req.URL.Query().Get(\"global\")\n\tvar globalBool bool\n\tif globalStr != \"\" {\n\t\tvar err error\n\t\tglobalBool, err = strconv.ParseBool(globalStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"Failed to parse value of %q (%v) as a bool: %v\", \"global\", globalStr, err)\n\t\t}\n\t}\n\targs.Global = globalBool\n\n\t// Parse the eval priority from the request URL query if present.\n\tevalPriority, err := parseInt(req, \"eval_priority\")","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/agent/job_endpoint.go#L611-L647","documentation":"jobDelete (command/agent/job_endpoint.go:629), called through jobCRUD when deleting a job, parses the ?purge= query parameter with strconv.ParseBool. If the supplied value is non-empty and not a valid boolean literal, the delete is rejected with 'Failed to parse value of \"purge\" (...) as a bool'. The job is not stopped or purged when this error occurs.","triggerScenarios":"DELETE /v1/job/<job-id>?purge=<bad value> — e.g. purge=yes, purge=Y, purge=on, purge=2 — anything outside strconv.ParseBool's accepted set (1/t/T/TRUE/true/True/0/f/F/FALSE/false/False).","commonSituations":"curl DELETE commands typed by hand with 'purge=yes'; scripts mapping shell Y/N prompts directly into the URL; API wrappers exposing purge as an arbitrary string; typos like purge=ture.","solutions":["Send purge=true (to purge) or purge=false; 1/0, t/f, T/F, TRUE/FALSE, True/False also work.","Omit ?purge entirely to take the default (false, normal stop without purge).","Check the echoed raw value in the error message for hidden characters or unexpanded variables.","Fix client code to serialize booleans via strconv.FormatBool or the language's native bool-to-string."],"exampleFix":"// before\ncurl -X DELETE 'http://127.0.0.1:4646/v1/job/web?purge=yes'\n// after\ncurl -X DELETE 'http://127.0.0.1:4646/v1/job/web?purge=true'","handlingStrategy":"validation","validationCode":"// Before DELETE /v1/job/<id>?purge=...\nif purge != \"\" {\n    if _, err := strconv.ParseBool(purge); err != nil {\n        return fmt.Errorf(\"purge must be a bool, got %q\", purge)\n    }\n}","typeGuard":"func isPurgeParam(s string) bool {\n    _, err := strconv.ParseBool(s)\n    return s == \"\" || err == nil\n}","tryCatchPattern":"resp, err := httpDo(http.MethodDelete, jobURL+\"?purge=\"+purge, nil)\nif err != nil { return err }\nif resp.StatusCode == 400 {\n    // 'Failed to parse value of \"purge\"' — correct the flag and retry once\n    return deleteJob(jobID, \"false\")\n}","preventionTips":["Use purge=true / purge=false verbatim in scripts.","Map shell Y/N prompts to Go-valid booleans before composing the URL.","Prefer omitting the param (default false) over guessing a value.","Validate all boolean flags with one shared helper."],"tags":["http","query-parameter","boolean","job-delete","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"}