cube-js/cube · critical

could not parse environment variable '{}' with '{}' value: {

Error message

could not parse environment variable '{}' with '{}' value: {}

What it means

The numeric environment-variable helper parses the variable's string value with `T::from_str` and panics if parsing fails, embedding the parse error in the message. It fires when an integer-typed Cube Store env var contains text that is not a valid number of the expected type.

Source

Thrown at rust/cubestore/cubestore/src/config/mod.rs:1458

        Err(_) => default,
    }
}

pub fn env_parse_duration<T>(name: &str, default: T, max: Option<T>, min: Option<T>) -> T
where
    T: FromStr + PartialOrd + Display,
    T::Err: Display,
{
    let v = match env::var(name).ok() {
        None => {
            return default;
        }
        Some(v) => v,
    };

    let n = match v.parse::<T>() {
        Ok(n) => n,
        Err(e) => panic!(
            "could not parse environment variable '{}' with '{}' value: {}",
            name, v, e
        ),
    };

    if let Some(max) = max {
        if n > max {
            panic!(
                "wrong configuration for environment variable '{}' with '{}' value: greater then max size {}",
                name, v,
                max
            )
        }
    };

    if let Some(min) = min {
        if n < min {
            panic!(

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Set the variable to a plain bare number valid for the expected type (e.g. `60000`, not `60s` or `1_000`).
  2. Convert unit-bearing values yourself: `60s` → `60000` (ms), `5m` → `300`.
  3. Check the parse error in the message for specifics (invalid digit vs. overflow) and correct the value accordingly.

Example fix

// before
CUBEJS_ROLLUP_ONLY_MAX_WORKER_THREADS=4x

// after
CUBEJS_ROLLUP_ONLY_MAX_WORKER_THREADS=4
Defensive patterns

Strategy: validation

Validate before calling

fn validate_int_env(name: &str) -> Result<(), String> {
    match std::env::var(name) {
        Ok(v) => v.trim().parse::<i64>().map(|_| ()).map_err(|e| format!("{}='{}' is not a valid integer: {}", name, v, e)),
        Err(_) => Ok(()),
    }
}
validate_int_env("CUBEJS_WORKER_THREADS")?;

Type guard

fn is_plain_integer(v: &str) -> bool {
    !v.trim().is_empty() && v.trim().chars().all(|c| c.is_ascii_digit())
}

Try / catch

// Launch-time guard: parse the same value the server will parse.
match "64s".parse::<usize>() {
    Ok(n) => println!("ok: {}", n),
    Err(e) => eprintln!("env value rejected by cubestore, fix before starting: {}", e),
}

Prevention

When it happens

Trigger: Setting a numeric Cube Store env var to a non-integer or out-of-type value — e.g. `VAR=1000ms` (suffix not allowed), `VAR=1_000` (underscores), `VAR=1.5` for an integer type, or a value that overflows the target type.

Common situations: Appending units to numbers out of habit; copy-pasting values with units or thousands separators; YAML/K8s manifests quoting values with whitespace; oversized numbers exceeding the integer type's range.

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 cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/926eb7bd153d1e04. Report an issue: GitHub.