Skip to content

Commit

Permalink
Merge pull request #245 from OpenTrafficCam/bug/2362-no-stacktrace-di…
Browse files Browse the repository at this point in the history
…splayed-on-console-when-exception-thrown

Bug/2362 no stacktrace displayed on console when exception thrown
  • Loading branch information
randy-seng authored Jun 22, 2023
2 parents 852bf48 + dd4ca88 commit 33ed7f7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
20 changes: 10 additions & 10 deletions OTAnalytics/application/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@ def clear_repositories(self) -> None:
self._video_repository.clear()

def load_video_files(self, files: list[Path]) -> None:
exception_messages = []
raised_exceptions: list[Exception] = []
videos = []
for file in files:
try:
videos.append(self._video_parser.parse(file))
except Exception as e:
exception_messages.append(str(e) + "\n")
if exception_messages:
raise OurCustomGroupException("\n".join(exception_messages))
except Exception as cause:
raised_exceptions.append(cause)
if raised_exceptions:
raise OurCustomGroupException(raised_exceptions)
self._video_repository.add_all(videos)

def remove_videos(self, videos: list[Video]) -> None:
Expand Down Expand Up @@ -339,14 +339,14 @@ def load_track_files(self, files: list[Path]) -> None:
Args:
file (Path): file in ottrk format
"""
exception_messages = []
raised_exceptions: list[Exception] = []
for file in files:
try:
self.load_track_file(file)
except Exception as e:
exception_messages.append(str(e) + "\n")
if exception_messages:
raise OurCustomGroupException("\n".join(exception_messages))
except Exception as cause:
raised_exceptions.append(cause)
if raised_exceptions:
raise OurCustomGroupException(raised_exceptions)

def get_all_tracks(self) -> list[Track]:
"""
Expand Down
7 changes: 6 additions & 1 deletion OTAnalytics/application/our_custom_group_exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class OurCustomGroupException(Exception):
"""Placeholder for ExceptionGroups introduced in Python 3.11"""

pass
def __init__(self, exceptions: list[Exception], *args: object) -> None:
super().__init__(*args)
self._exceptions = exceptions

def __str__(self) -> str:
return "\n".join([str(exception) for exception in self._exceptions])
2 changes: 2 additions & 0 deletions OTAnalytics/plugin_ui/customtkinter_gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tkinter
import traceback
from typing import Any

from customtkinter import (
Expand Down Expand Up @@ -39,6 +40,7 @@ def report_callback_exception(self, exc: Any, val: Any, tb: Any) -> None:
InfoBox(
message=str(val), title="Error", initial_position=get_widget_position(self)
)
traceback.print_exception(val)


class TabviewInputFiles(CTkTabview):
Expand Down

0 comments on commit 33ed7f7

Please sign in to comment.