cube-js/cube · error

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

Error message

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

What it means

env_optparse parses an environment variable into any FromStr type and panics if the value can't be parsed, embedding the variable name, raw value, and parse error. CubeSQL treats a malformed typed env var as a fatal startup misconfiguration.

Source

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

    }
}

pub fn env_parse<T>(name: &str, default: T) -> T
where
    T: FromStr,
    T::Err: Display,
{
    env_optparse(name).unwrap_or(default)
}

fn env_optparse<T>(name: &str) -> Option<T>
where
    T: FromStr,
    T::Err: Display,
{
    env::var(name).ok().map(|x| match x.parse::<T>() {
        Ok(v) => v,
        Err(e) => panic!(
            "Could not parse environment variable '{}' with '{}' value: {}",
            name, x, e
        ),
    })
}

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,
    };

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Check the panic message for the variable name and offending value, then set a valid value for that type (integer, bool, etc.)
  2. Use the exact literal formats the type parses (e.g. 'true'/'false', plain integers, no spaces/quotes)
  3. Unset the variable to fall back to the default if a custom value isn't required

Example fix

// before
CUBEJS_DB_MAX_POOL_SIZE=ten
// after
CUBEJS_DB_MAX_POOL_SIZE=10
Defensive patterns

Strategy: validation

Validate before calling

// Validate env values before the process relies on them (shell preflight)
check_int() { case "$1" in ''|*[!0-9]*) echo "invalid integer: $1"; exit 1;; esac; }
check_bool() { case "$1" in true|false) ;; *) echo "invalid bool (use true/false): $1"; exit 1;; esac }
[ -n "$CUBEJS_DB_MAX_POOL_SIZE" ] && check_int "$CUBEJS_DB_MAX_POOL_SIZE"

Prevention

When it happens

Trigger: Setting an env var consumed via env_optparse/env_parse to a value the target type can't parse — e.g. a numeric option set to 'abc', a boolean set to 'yes' where only 'true'/'false' parse, or a hex/undecodable port number.

Common situations: Docker/K8s manifests with wrong env values; quoting issues that add stray spaces; editing configs by hand and using locale-specific number formats.

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/97f08c44e668f8d4. Report an issue: GitHub.