Skip to content

Commit dda066a

Browse files
rsashankneiljp
authored andcommitted
core: Enable copying traceback when exceptions occur.
Added functionality for users to copy the traceback from the exception popup, making it convenient for bug or feature reports. Fixes #1493.
1 parent 95df188 commit dda066a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

zulipterminal/core.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing_extensions import Literal
2020

2121
from zulipterminal.api_types import Composition, Message
22+
from zulipterminal.config.keys import primary_display_key_for_command
2223
from zulipterminal.config.symbols import POPUP_CONTENT_BORDER, POPUP_TOP_LINE
2324
from zulipterminal.config.themes import ThemeSpec
2425
from zulipterminal.config.ui_sizes import (
@@ -35,6 +36,7 @@
3536
EditHistoryView,
3637
EditModeView,
3738
EmojiPickerView,
39+
ExceptionView,
3840
FullRawMsgView,
3941
FullRenderedMsgView,
4042
HelpView,
@@ -300,6 +302,11 @@ def show_stream_members(self, stream_id: int) -> None:
300302
def popup_with_message(self, text: str, width: int) -> None:
301303
self.show_pop_up(NoticeView(self, text, width, "NOTICE"), "area:error")
302304

305+
def show_exception_popup(self, text: str, width: int, traceback: str) -> None:
306+
self.show_pop_up(
307+
ExceptionView(self, text, width, "EXCEPTION", traceback), "area:error"
308+
)
309+
303310
def show_about(self) -> None:
304311
self.show_pop_up(
305312
AboutView(
@@ -709,8 +716,12 @@ def _raise_exception(self, *args: Any, **kwargs: Any) -> Literal[True]:
709716
+ "\n\n"
710717
+ "Details of the exception can be found in "
711718
+ exception_logfile
719+
+ "\n\n"
720+
+ f"Press [{primary_display_key_for_command('COPY_TRACEBACK')}]"
721+
+ " to copy traceback to clipboard."
712722
)
713-
self.popup_with_message(message, width=80)
723+
full_traceback = "".join(traceback.format_exception(*exc))
724+
self.show_exception_popup(message, traceback=full_traceback, width=80)
714725
self._exception_info = None
715726
return True # If don't raise, retain pipe
716727

0 commit comments

Comments
 (0)