hashicorp/nomad · error

Failed to parse value of %q (%v) as a bool: %v

Error message

Failed to parse value of %q (%v) as a bool: %v

What it means

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.

Source

Thrown at command/agent/job_endpoint.go:629

	}
	setIndex(resp, out.Index)
	return out, nil
}

func (s *HTTPServer) jobDelete(resp http.ResponseWriter, req *http.Request, jobID string) (any, error) {

	args := structs.JobDeregisterRequest{
		JobID: jobID,
	}

	// Identify the purge query param and parse.
	purgeStr := req.URL.Query().Get("purge")
	var purgeBool bool
	if purgeStr != "" {
		var err error
		purgeBool, err = strconv.ParseBool(purgeStr)
		if err != nil {
			return nil, fmt.Errorf("Failed to parse value of %q (%v) as a bool: %v", "purge", purgeStr, err)
		}
	}
	args.Purge = purgeBool

	// Identify the global query param and parse.
	globalStr := req.URL.Query().Get("global")
	var globalBool bool
	if globalStr != "" {
		var err error
		globalBool, err = strconv.ParseBool(globalStr)
		if err != nil {
			return nil, fmt.Errorf("Failed to parse value of %q (%v) as a bool: %v", "global", globalStr, err)
		}
	}
	args.Global = globalBool

	// Parse the eval priority from the request URL query if present.
	evalPriority, err := parseInt(req, "eval_priority")

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Send purge=true (to purge) or purge=false; 1/0, t/f, T/F, TRUE/FALSE, True/False also work.
  2. Omit ?purge entirely to take the default (false, normal stop without purge).
  3. Check the echoed raw value in the error message for hidden characters or unexpanded variables.
  4. Fix client code to serialize booleans via strconv.FormatBool or the language's native bool-to-string.

Example fix

// before
curl -X DELETE 'http://127.0.0.1:4646/v1/job/web?purge=yes'
// after
curl -X DELETE 'http://127.0.0.1:4646/v1/job/web?purge=true'
Defensive patterns

Strategy: validation

Validate before calling

// Before DELETE /v1/job/<id>?purge=...
if purge != "" {
    if _, err := strconv.ParseBool(purge); err != nil {
        return fmt.Errorf("purge must be a bool, got %q", purge)
    }
}

Type guard

func isPurgeParam(s string) bool {
    _, err := strconv.ParseBool(s)
    return s == "" || err == nil
}

Try / catch

resp, err := httpDo(http.MethodDelete, jobURL+"?purge="+purge, nil)
if err != nil { return err }
if resp.StatusCode == 400 {
    // 'Failed to parse value of "purge"' — correct the flag and retry once
    return deleteJob(jobID, "false")
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/a3e6bd52db29abb6. Report an issue: GitHub.