{"record":{"id":"b7e14e1b6436ecdb","repo":"google-gemini/gemini-cli","slug":"environment-variable-firestore-doc-is-required-b","errorCode":null,"errorMessage":"Environment variable 'FIRESTORE_DOC' is required but was not set.","messagePattern":"Environment variable 'FIRESTORE_DOC' is required but was not set\\.","errorType":"validation","errorClass":"ConfigurationError","httpStatus":null,"severity":"critical","filePath":"tools/caretaker-agent/cloudrun/pr-generator/workflow/config.py","lineNumber":70,"sourceCode":"            self.repo_url.rstrip(\"/\").split(\"/\")[-1].replace(\".git\", \"\")\n        )\n        self.pr_repo_path: str = os.path.join(self.pr_dir, self.repo_name)\n        self.eval_repo_path: str = os.path.join(self.eval_dir, self.repo_name)\n\n        # Global environment variables to trust the CLI\n        os.environ[\"GEMINI_CLI_WORKSPACE_TRUSTED\"] = \"true\"\n\n    def load_and_validate_firestore_doc(self) -> dict[str, Any]:\n        \"\"\"Parses and validates the Firestore JSON input specification.\n\n        Returns:\n            The decoded dictionary of the Firestore document.\n\n        Raises:\n            ConfigurationError: If the document is missing or not valid JSON.\n        \"\"\"\n        if not self.firestore_doc_raw:\n            raise ConfigurationError(\n                \"Environment variable 'FIRESTORE_DOC' is required but was not set.\"\n            )\n        try:\n            doc_data = json.loads(self.firestore_doc_raw)\n            if not isinstance(doc_data, dict):\n                raise ConfigurationError(\n                    \"Firestore document specification must be a JSON object.\"\n                )\n            return doc_data\n        except json.JSONDecodeError as e:\n            raise ConfigurationError(\n                f\"Failed to parse 'FIRESTORE_DOC' as JSON: {e}\"\n            ) from e\n","sourceCodeStart":52,"sourceCodeEnd":84,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/tools/caretaker-agent/cloudrun/pr-generator/workflow/config.py#L52-L84","documentation":"ConfigurationError 'Environment variable FIRESTORE_DOC is required but was not set.' is raised by load_and_validate_firestore_doc when self.firestore_doc_raw is falsy. The PR-generator CloudRun service expects every invocation to carry a FIRESTORE_DOC env var describing the job; without it the service cannot proceed.","triggerScenarios":"Configuration().firestore_doc_raw (read from FIRESTORE_DOC env at construction) is empty/None -> load_and_validate_firestore_doc() -> `if not self.firestore_doc_raw: raise ConfigurationError(...)`.","commonSituations":"Cloud Function/Run deploy missing the FIRESTORE_DOC env var; test harness invoking the service locally without setting it; Firestore trigger wiring changed and no longer passes the doc JSON.","solutions":["Set FIRESTORE_DOC to a valid JSON document string in the CloudRun service env.","If testing locally, export FIRESTORE_DOC='{}' (then satisfy [256] by filling it).","Verify the upstream Firestore trigger / scheduler still writes the env var on each invocation."],"exampleFix":"# before\n# env: (FIRESTORE_DOC unset)\n# after\nexport FIRESTORE_DOC='{\"issue_number\": 42, \"owner\": \"org\", \"repo\": \"name\"}'","handlingStrategy":"validation","validationCode":"raw = os.environ.get('FIRESTORE_DOC')\nif not raw:\n    raise SystemExit('FIRESTORE_DOC env var required')","typeGuard":"def is_missing_firestore_doc(e: Exception) -> bool:\n    return isinstance(e, ConfigurationError) and 'FIRESTORE_DOC' in str(e) and 'not set' in str(e)","tryCatchPattern":"try:\n    doc = cfg.load_and_validate_firestore_doc()\nexcept ConfigurationError as e:\n    if 'not set' in str(e): raise SystemExit('configure FIRESTORE_DOC env var')\n    raise","preventionTips":["Add a startup assertion for FIRESTORE_DOC so missing-env fails the deploy loudly.","Keep the env var name in the service's documented required-env list."],"tags":["configuration","env-vars","firestore","cloudrun","python"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}