mirror of
https://github.com/GuDaStudio/codexmcp.git
synced 2026-02-04 01:50:40 +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:
@@ -221,15 +221,18 @@ async def codex(
|
||||
err_message = "codex error: " + line_dict.get("error", {}).get("message", "")
|
||||
if "error" in line_dict.get("type", ""):
|
||||
error_msg = line_dict.get("message", "")
|
||||
import re
|
||||
is_reconnecting = bool(re.match(r'^Reconnecting\.\.\.\s+\d+/\d+$', error_msg))
|
||||
|
||||
if not is_reconnecting:
|
||||
success = False if len(agent_messages) == 0 else success
|
||||
err_message = "codex error: " + error_msg
|
||||
except json.JSONDecodeError as error:
|
||||
# Improved error handling: include problematic line
|
||||
err_message = line
|
||||
success = False
|
||||
break
|
||||
|
||||
except json.JSONDecodeError:
|
||||
import sys
|
||||
print(f"Ignored non-JSON line: {line}", file=sys.stderr)
|
||||
continue
|
||||
|
||||
except Exception as error:
|
||||
err_message = f"Unexpected error: {error}. Line: {line!r}"
|
||||
success = False
|
||||
|
||||
Reference in New Issue
Block a user