Skip to content

Commit 332633b

Browse files
Kasper Jungeclaude
authored andcommitted
refactor: improve exception handling for better debuggability
- Include full traceback in engine crash events so errors are diagnosable - Narrow primitives API base64 decoder to catch only expected exceptions - Display traceback in console emitter when available Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fad99b8 commit 332633b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/ralphify/_console_emitter.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def _on_log_message(self, d: dict) -> None:
7676
level = d.get("level", "info")
7777
if level == "error":
7878
self._rprint(f"[red]{msg}[/red]")
79+
tb = d.get("traceback")
80+
if tb:
81+
self._rprint(f"[dim]{tb}[/dim]")
7982
else:
8083
self._rprint(f"[dim]{msg}[/dim]")
8184

src/ralphify/engine.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111
import sys
1212
import time
13+
import traceback
1314
import threading
1415
from dataclasses import dataclass, field
1516
from datetime import datetime
@@ -491,10 +492,15 @@ def run_loop(
491492
pass
492493
except Exception as exc:
493494
state.status = RunStatus.FAILED
495+
tb = traceback.format_exc()
494496
emitter.emit(Event(
495497
type=EventType.LOG_MESSAGE,
496498
run_id=state.run_id,
497-
data={"message": f"Run crashed: {exc}", "level": "error"},
499+
data={
500+
"message": f"Run crashed: {exc}",
501+
"level": "error",
502+
"traceback": tb,
503+
},
498504
))
499505

500506
if state.status == RunStatus.RUNNING:

src/ralphify/ui/api/primitives.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _decode_project_dir(encoded: str) -> Path:
3636
"""Decode a base64-encoded project directory path."""
3737
try:
3838
return Path(base64.urlsafe_b64decode(encoded).decode())
39-
except Exception:
39+
except (ValueError, UnicodeDecodeError):
4040
raise HTTPException(status_code=400, detail="Invalid base64 project_dir")
4141

4242

0 commit comments

Comments
 (0)