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

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.

Source

Thrown at command/agent/http.go:1048

	} else if *n == "" {
		*n = structs.DefaultNamespace
	}
}

// parseIdempotencyToken is used to parse the ?idempotency_token parameter
func parseIdempotencyToken(req *http.Request, n *string) {
	if idempotencyToken := req.URL.Query().Get("idempotency_token"); idempotencyToken != "" {
		*n = idempotencyToken
	}
}

// parseBool parses a query parameter to a boolean or returns (nil, nil) if the
// parameter is not present.
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 &param, 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 &param, nil
	}
	return nil, nil

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. 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).
  2. Remove the query parameter entirely if you do not need it; absent parameters are treated as nil and do not error.
  3. 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.
  4. If you own client code, cast/serialize the value to a proper boolean before appending it to the URL.

Example fix

// before
curl 'http://127.0.0.1:4646/v1/jobs?stale=yes'
// after
curl 'http://127.0.0.1:4646/v1/jobs?stale=true'
Defensive patterns

Strategy: validation

Validate before calling

// Validate a boolean query param before calling the Nomad API
func validBoolParam(v string) bool {
    _, err := strconv.ParseBool(v)
    return err == nil
}
// if !validBoolParam(stale) { fix before requesting }

Type guard

func isGoBool(s string) bool {
    switch s {
    case "1", "t", "T", "true", "TRUE", "True", "0", "f", "F", "false", "FALSE", "False":
        return true
    }
    return false
}

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 bool
    return fmt.Errorf("bad query param: %s", body)
}

Prevention

When it happens

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

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

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/2a9beb811511dea1. Report an issue: GitHub.