cube-js/cube · error
could not parse environment variable '{}' with '{}' value: {
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.
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)
Solutions
- Set the value as <number><supported unit> matching what the code strips (e.g. '60s', '10m'), or a bare number if unitless is accepted
- Trim whitespace and remove surrounding quotes from the env value
- 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
- Express durations as plain numbers with a single unit suffix (300s, 5m, 1h)
- Avoid prose values like 'every few minutes' in env files
- Watch for CI-injected trailing whitespace/newlines in secrets and env vars
- Document the exact accepted formats next to each duration variable
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
- Could not parse environment variable '{}' with '{}' value: {
- This query doesnt have a plan, because it already has values
- Should be rewritten with UtcTimestamp function
- CreateExternalTable is not supported
- Explain is not supported
AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02).
Data as JSON: /api/errors/a324b2577f4fa67b.
Report an issue: GitHub.