{"record":{"id":"e8da752ef300dc42","repo":"calesthio/OpenMontage","slug":"required-environment-variable-key-r-is-not-set","errorCode":null,"errorMessage":"Required environment variable {key!r} is not set","messagePattern":"Required environment variable (.+?) is not set","errorType":"exception","errorClass":"EnvironmentError","httpStatus":null,"severity":"error","filePath":"lib/env_loader.py","lineNumber":33,"sourceCode":"def load_env(project_root: Optional[Path] = None) -> None:\n    \"\"\"Load .env file from project root.\"\"\"\n    if project_root is None:\n        project_root = Path(__file__).resolve().parent.parent\n    env_path = project_root / \".env\"\n    if env_path.exists():\n        load_dotenv(env_path)\n\n\ndef get_env(key: str, default: Optional[str] = None) -> Optional[str]:\n    \"\"\"Get an environment variable with optional default.\"\"\"\n    return os.environ.get(key, default)\n\n\ndef require_env(key: str) -> str:\n    \"\"\"Get a required environment variable. Raises if missing.\"\"\"\n    value = os.environ.get(key)\n    if value is None:\n        raise EnvironmentError(f\"Required environment variable {key!r} is not set\")\n    return value\n","sourceCodeStart":15,"sourceCodeEnd":35,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/lib/env_loader.py#L15-L35","documentation":"Raised by lib/env_loader.py's require_env() when os.environ does not contain the requested key. require_env is the strict variant of get_env: get_env returns a default, require_env raises EnvironmentError so startup fails fast instead of passing None into downstream code. It is the standard way OpenMontage enforces that provider keys (API keys, tokens) exist before any paid or network call is made.","triggerScenarios":"Calling require_env('ATLASCLOUD_API_KEY') (or any other key) when the variable is unset — e.g. no .env file at the expected env_path, load_dotenv pointed at the wrong file, or the process launched from an environment that never exported the variable.","commonSituations":"Fresh clone without a .env; CI runner missing secret configuration; variable name typo or renamed key after a version upgrade; .env present but load_dotenv was never called or was called with an incorrect path.","solutions":["Create/extend the project .env file with the missing key and rerun.","Verify load_dotenv(env_path) is called with the correct path before require_env, and that the file is named/located as expected.","Export the variable in the shell or CI environment (export KEY=value) if .env is not used.","If the key is optional for your flow, use get_env(key, default) instead of require_env."],"exampleFix":"# before\nkey = require_env(\"ATLASCLOUD_API_KEY\")  # raises if unset\n\n# after\nfrom lib.env_loader import load_dotenv, get_env, require_env\nload_dotenv(PROJECT_DIR / \".env\")  # ensure .env is loaded first\nkey = require_env(\"ATLASCLOUD_API_KEY\")","handlingStrategy":"validation","validationCode":"import os\nfrom lib.env_loader import get_env\n\nmissing = [k for k in REQUIRED_KEYS if not get_env(k)]\nif missing:\n    raise SystemExit(f\"Missing env vars: {', '.join(missing)}\")","typeGuard":"def env_is_set(key: str) -> bool:\n    return bool(os.environ.get(key))","tryCatchPattern":"try:\n    api_key = require_env(\"ATLASCLOUD_API_KEY\")\nexcept EnvironmentError as e:\n    raise SystemExit(f\"Startup blocked: {e}. Add it to .env and rerun.\") from e","preventionTips":["Call load_dotenv with an explicit, correct env_path at process start.","Validate all required keys in one preflight loop before any work begins.","Keep a checked-in .env.example listing every key require_env consumes.","Prefer get_env with defaults for optional keys; reserve require_env for true hard dependencies."],"tags":["environment","configuration","secrets","startup"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}