{"record":{"id":"a72daaa25be27d86","repo":"google-gemini/gemini-cli","slug":"failed-to-parse-firestore-doc-as-json-e","errorCode":null,"errorMessage":"Failed to parse 'FIRESTORE_DOC' as JSON: {e}","messagePattern":"Failed to parse 'FIRESTORE_DOC' as JSON: (.+?)","errorType":"validation","errorClass":"ConfigurationError","httpStatus":null,"severity":"critical","filePath":"tools/caretaker-agent/cloudrun/pr-generator/workflow/config.py","lineNumber":81,"sourceCode":"        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":63,"sourceCodeEnd":84,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/tools/caretaker-agent/cloudrun/pr-generator/workflow/config.py#L63-L84","documentation":"ConfigurationError 'Failed to parse FIRESTORE_DOC as JSON: e' wraps a json.JSONDecodeError raised when load_and_validate_firestore_doc calls json.loads on firestore_doc_raw. The original decode error (position, message) is preserved via `from e`.","triggerScenarios":"self.firestore_doc_raw is truthy but not valid JSON -> json.loads raises JSONDecodeError -> except json.JSONDecodeError as e: raise ConfigurationError(f\"Failed to parse 'FIRESTORE_DOC' as JSON: {e}\") from e.","commonSituations":"Trailing comma in the env JSON; single quotes instead of double quotes; unescaped newlines inside strings; copy-paste introduced smart quotes; the env var was double-quoted at deploy time and now contains a leading/trailing quote char.","solutions":["Run the value through a JSON validator / `python -m json.tool` and fix the syntax error at the reported position.","Re-deploy the CloudRun service with the corrected FIRESTORE_DOC value.","If the doc is generated upstream, fix the publisher to emit strict JSON."],"exampleFix":"# before\nexport FIRESTORE_DOC=\"{'issue_number': 42,}\"  # single quotes + trailing comma\n# after\nexport FIRESTORE_DOC='{\"issue_number\": 42}'","handlingStrategy":"validation","validationCode":"import json\ntry:\n    json.loads(os.environ['FIRESTORE_DOC'])\nexcept json.JSONDecodeError as e:\n    raise SystemExit(f'FIRESTORE_DOC is not valid JSON: {e}')","typeGuard":"def is_firestore_json_parse_error(e: Exception) -> bool:\n    return isinstance(e, ConfigurationError) and 'parse' in str(e).lower() and 'FIRESTORE_DOC' in str(e)","tryCatchPattern":"try:\n    doc = cfg.load_and_validate_firestore_doc()\nexcept ConfigurationError as e:\n    if 'parse' in str(e).lower(): raise SystemExit('fix FIRESTORE_DOC JSON syntax')\n    raise","preventionTips":["Lint the env value with `python -m json.tool` at deploy time.","Generate FIRESTORE_DOC programmatically (json.dumps) instead of hand-editing."],"tags":["configuration","json-parse","firestore","python"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}