1
0
mirror of https://github.com/GuDaStudio/codexmcp.git synced 2026-02-05 02:00:24 +08:00

Enhance error handling for JSON decoding (#24)

Improve error handling for non-JSON lines by printing to stderr instead of breaking the flow.
This commit is contained in:
Abner
2025-12-01 11:39:12 +08:00
committed by GitHub
parent d8debc6182
commit e6931e6888

View File

@@ -221,15 +221,18 @@ async def codex(
err_message = "codex error: " + line_dict.get("error", {}).get("message", "") err_message = "codex error: " + line_dict.get("error", {}).get("message", "")
if "error" in line_dict.get("type", ""): if "error" in line_dict.get("type", ""):
error_msg = line_dict.get("message", "") error_msg = line_dict.get("message", "")
import re
is_reconnecting = bool(re.match(r'^Reconnecting\.\.\.\s+\d+/\d+$', error_msg)) is_reconnecting = bool(re.match(r'^Reconnecting\.\.\.\s+\d+/\d+$', error_msg))
if not is_reconnecting: if not is_reconnecting:
success = False if len(agent_messages) == 0 else success success = False if len(agent_messages) == 0 else success
err_message = "codex error: " + error_msg err_message = "codex error: " + error_msg
except json.JSONDecodeError as error:
# Improved error handling: include problematic line except json.JSONDecodeError:
err_message = line import sys
success = False print(f"Ignored non-JSON line: {line}", file=sys.stderr)
break continue
except Exception as error: except Exception as error:
err_message = f"Unexpected error: {error}. Line: {line!r}" err_message = f"Unexpected error: {error}. Line: {line!r}"
success = False success = False