{"record":{"id":"ab0eda298e42fbff","repo":"cube-js/cube","slug":"unknown-env-variable","errorCode":null,"errorMessage":"unknown env variable {}","messagePattern":"unknown env variable (.+?)","errorType":"exception","errorClass":"minijinja::Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-native/src/template/entry.rs","lineNumber":45,"sourceCode":"        let debug_info = options\n            .get_value(cx, \"debugInfo\")?\n            .downcast_or_throw::<JsBoolean, _>(cx)?\n            .value(cx);\n\n        let mut engine = mj::Environment::new();\n        engine.set_debug(debug_info);\n        engine.add_function(\n            \"env_var\",\n            |var_name: String, var_default: Option<String>, _state: &minijinja::State| {\n                if let Ok(value) = std::env::var(&var_name) {\n                    return Ok(mj::value::Value::from(value));\n                }\n\n                if let Some(var_default) = var_default {\n                    return Ok(mj::value::Value::from(var_default));\n                }\n\n                let err = minijinja::Error::new(\n                    mj::ErrorKind::InvalidOperation,\n                    format!(\"unknown env variable {}\", var_name),\n                );\n\n                Err(err)\n            },\n        );\n        engine.set_auto_escape_callback(|_name: &str| mj::AutoEscape::Json);\n\n        #[cfg(feature = \"python\")]\n        engine_python::mj_inject_python_extension(cx, options, &mut engine)?;\n\n        let workers_count = {\n            let workers_count_float = options\n                .get_value(cx, \"workers\")?\n                .downcast_or_throw::<JsNumber, _>(cx)?\n                .value(cx);\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-native/src/template/entry.rs#L27-L63","documentation":"The native backend's MiniJinja `env` function resolves environment variables for templates. When the requested variable is not set and no default was provided, it raises `unknown env variable {var_name}` as an `InvalidOperation` error. Unlike Python's `os.environ[...]`, there is no lenient mode unless the template supplies a default via the function's arguments.","triggerScenarios":"A data model/template calls `env('SOME_VAR')` where `SOME_VAR` is not present in the process environment and the call supplies no `var_default` argument.","commonSituations":"Deploying to a new environment where required env vars weren't configured, typos in variable names, secrets defined in one environment (CI) but not another (local dev), container missing `-e` flags.","solutions":["Export/set the missing environment variable before starting the Cube process.","Add a default in the template: `env('VAR', 'default')`.","Fix the variable name typo in the data model.","Ensure your deployment (Docker/K8s) passes the variable into the container."],"exampleFix":"// before\n{{ env('CUBE_API_SECRET') }}\n// after\n{{ env('CUBE_API_SECRET', 'dev-secret') }}","handlingStrategy":"fallback","validationCode":"// in shell, before starting Cube:\n[ -n \"$CUBE_API_SECRET\" ] || { echo \"CUBE_API_SECRET is not set\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply a default as the second argument to env(): env('VAR', 'fallback')","Document required env vars and check them at deploy time","Use a .env file / secret manager wired into every environment","Grep data models for env('...') calls and ensure each is set in all environments"],"tags":["environment","template","minijinja","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}