clan-app: full context tracebacks

If an exception now is thrown in one of the middlewares we will get a
proper traceback instead of a cut off one like before
This commit is contained in:
Qubasa
2025-09-30 15:13:40 +02:00
parent 8ad9f99606
commit fdc4b5f769
6 changed files with 65 additions and 49 deletions

View File

@@ -12,6 +12,25 @@ class MiddlewareContext:
request: "BackendRequest"
bridge: "ApiBridge"
exit_stack: ExitStack
original_traceback: list[str]
class MiddlewareError(Exception):
"""Exception that preserves original calling context."""
def __init__(
self, message: str, original_frames: list[str], original_error: Exception
) -> None:
# Store just the original error message for API responses
super().__init__(str(original_error))
self.method_message = message
self.original_frames = original_frames
self.original_error = original_error
def __str__(self) -> str:
# For traceback display, show in proper Python traceback order (oldest to newest)
original_context = "".join(self.original_frames)
return f"Traceback (most recent call last):\n{original_context.rstrip()}\nMethodExecutionError: {self.original_error}"
@dataclass(frozen=True)