Skip to content

Commit

Permalink
Report full traceback and path at exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Feb 9, 2024
1 parent f80f304 commit f056f7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions renumics/spotlight/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ def _() -> None:
self.include_router(plugin_api.router, prefix="/api/plugins")

@self.exception_handler(Exception)
async def _(_: Request, e: Exception) -> JSONResponse:
async def _(request: Request, e: Exception) -> JSONResponse:
if settings.verbose:
logger.exception(e)
else:
logger.info(e)
emit_exception_event()
emit_exception_event(request.url.path)
class_name = type(e).__name__
title = re.sub(r"([a-z])([A-Z])", r"\1 \2", class_name)
return JSONResponse(
Expand All @@ -219,11 +219,12 @@ async def _(_: Request, e: Exception) -> JSONResponse:
)

@self.exception_handler(Problem)
async def _(_: Request, problem: Problem) -> JSONResponse:
async def _(request: Request, problem: Problem) -> JSONResponse:
if settings.verbose:
logger.exception(problem)
else:
logger.info(problem)
emit_exception_event(request.url.path)
return JSONResponse(
{
"title": problem.title,
Expand Down
12 changes: 7 additions & 5 deletions renumics/spotlight/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import threading
import time
import traceback
from functools import wraps
from os import environ
from typing import Any, Callable, Dict, Optional, Union
Expand Down Expand Up @@ -171,14 +172,15 @@ def emit_exit_event() -> None:
report_event({"type": "spotlight_exit"})


def emit_exception_event() -> None:
def emit_exception_event(path: Optional[str] = None) -> None:
"""
Emit an exception event.
"""
ex_type, ex_value, _ = sys.exc_info()
detail = str(ex_value)
if ex_type is not None:
detail = f"{ex_type.__name__}: {ex_value}"
detail = traceback.format_exc()

if path:
detail = f"Path: {path}\n{detail}"

report_event(
{
"type": "spotlight_exception",
Expand Down

0 comments on commit f056f7c

Please sign in to comment.