cube-js/cube · error

could not parse environment variable

Error message

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

What it means

env_parse_duration parses an env var into a duration-like value: it first reads a unit suffix, then parses the numeric part with T::from_str. If the numeric part fails to parse it panics with the variable name, raw value, and underlying parse error. It also enforces an optional maximum afterwards.

Solutions

  1. Set the value as <number><supported unit> matching what the code strips (e.g. '60s', '10m'), or a bare number if unitless is accepted
  2. Trim whitespace and remove surrounding quotes from the env value
  3. Unset the variable to use the built-in default

Example fix

// before
CUBEJS_REFRESH_WIFI=every few minutes
// after
CUBEJS_REFRESH_WIFI=300s
Defensive patterns

Strategy: validation

Validate before calling

// Validate duration env vars: number + supported unit
check_duration() {
  echo "$1" | grep -Eq '^[0-9]+(s|m|h|ms)?$' || { echo "invalid duration '$1' (expected e.g. 30s, 5m)"; exit 1; }
}
[ -n "$CUBEJS_REFRESH_WIFI" ] && check_duration "$CUBEJS_REFRESH_WIFI"

Prevention

When it happens

Trigger: Setting a duration env var (e.g. cache/connect timeouts) to a value whose numeric component is unparseable — 'abc s', '5minutes' with an unsupported unit path, or trailing whitespace/quotes.

Common situations: Hand-edited deployment configs using human-friendly values ('5 min', '30seconds') instead of the supported numeric+unit format; CI secrets with stray spaces or newline characters.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/a324b2577f4fa67b. Report an issue: GitHub.

Appendix: source

Thrown at rust/cubesql/cubesql/src/config/mod.rs:475

        ),
    })
}

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)