Safely parses a JSON string into a dictionary. Logs a warning if the JSON is invalid and returns an empty dictionary. Args: text: The JSON string to parse. Returns: A dictionary representing the parsed JSON, or an empty dictionary on error.
(text: str)
| 182 | # Utility functions |
| 183 | # -------------------------------------------------------------------- |
| 184 | def parse_json_message(text: str) -> dict: |
| 185 | """ |
| 186 | Safely parses a JSON string into a dictionary. |
| 187 | |
| 188 | Logs a warning if the JSON is invalid and returns an empty dictionary. |
| 189 | |
| 190 | Args: |
| 191 | text: The JSON string to parse. |
| 192 | |
| 193 | Returns: |
| 194 | A dictionary representing the parsed JSON, or an empty dictionary on error. |
| 195 | """ |
| 196 | try: |
| 197 | return json.loads(text) |
| 198 | except json.JSONDecodeError: |
| 199 | logger.warning("🖥️⚠️ Ignoring client message with invalid JSON") |
| 200 | return {} |
| 201 | |
| 202 | def format_timestamp_ns(timestamp_ns: int) -> str: |
| 203 | """ |
no outgoing calls
no test coverage detected