t8y2/dbx · error · ValueError

{name} must be a boolean

Error message

{name} must be a boolean

What it means

env_bool() parses an environment variable as a boolean, accepting 1/true/yes/on and 0/false/no/off case-insensitively. If the value is any other non-empty string it raises ValueError with the variable name. Empty/unset values fall back to the default instead.

Source

Thrown at agents/drivers/hive-go/bench/agent_compare.py:660


def env_float(name: str, fallback: float) -> float:
    value = float(env_default(name, str(fallback)))
    if value <= 0:
        raise ValueError(f"{name} must be positive")
    return value


def env_bool(name: str, fallback: bool) -> bool:
    raw = os.getenv(name)
    if raw is None or raw == "":
        return fallback
    normalized = raw.strip().lower()
    if normalized in {"1", "true", "yes", "on"}:
        return True
    if normalized in {"0", "false", "no", "off"}:
        return False
    raise ValueError(f"{name} must be a boolean")


if __name__ == "__main__":
    main()

View on GitHub (pinned to c0390bff16)

Solutions

  1. Set the variable to one of: 1, true, yes, on, 0, false, no, off (any case)
  2. Unset or empty the variable to use the fallback
  3. Fix the typo in the value (e.g. TURE -> true)
  4. Wrap the read in try/except ValueError if a non-boolean value should degrade to the default

Example fix

// before
export BENCH_TLS=enabled
// after
export BENCH_TLS=true
Defensive patterns

Strategy: validation

Validate before calling

TRUE_VALUES = {"1", "true", "yes", "on"}
FALSE_VALUES = {"0", "false", "no", "off"}

def valid_bool_env(name: str, default: bool) -> bool:
    raw = os.getenv(name)
    if raw is None or raw == "":
        return default
    normalized = raw.strip().lower()
    if normalized in TRUE_VALUES:
        return True
    if normalized in FALSE_VALUES:
        return False
    raise SystemExit(f"{name} must be one of {sorted(TRUE_VALUES | FALSE_VALUES)}")

Try / catch

try:
    use_tls = env_bool("BENCH_TLS", False)
except ValueError as e:
    print(f"bad boolean: {e}; defaulting to False")
    use_tls = False

Prevention

When it happens

Trigger: connection_params reads a boolean env var whose value is a typo or unexpected word, e.g. BENCH_TLS="enabled" or "TURE" — anything not in the two accepted sets after strip().lower().

Common situations: Using "y"/"n", "enable"/"disable", or "True " with odd casing is fine but "on/off" misspellings are not; values copied from other tools with different boolean conventions (e.g. "1 " fine, "yes!" not).

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/56ace50a860b7ecf. Report an issue: GitHub.