zulip-terminal
zulip-terminal copied to clipboard
Copy traceback from the Exception popup
Allow copying traceback from the Exception has occurred popup.
External discussion & connections
- [x] Discussed in #zulip-terminal in
View object has no attribute topic_w - [ ] Fully fixes #
- [x] Partially fixes issue #1493
- [ ] Builds upon previous unmerged work in PR #
- [ ] Is a follow-up to work in PR #
- [ ] Requires merge of PR #
- [ ] Merge will enable work on #
How did you test this?
- [x] Manually - Behavioral changes
- [x] Manually - Visual changes
- [ ] Adapting existing automated tests
- [ ] Adding automated tests for new behavior (or missing tests)
- [ ] Existing automated tests should already cover this (only a refactor of tested code)
Self-review checklist for each commit
- [x] It is a minimal coherent idea
- [x] It has a commit summary following the documented style (title & body)
- [x] It has a commit summary describing the motivation and reasoning for the change
- [x] It individually passes linting and tests
- [ ] It contains test additions for any new behavior
- [x] It flows clearly from a previous branch commit, and/or prepares for the next commit
Visual changes
| Before | After |
|---|---|
| Traceback copy feature wasn't available before |
Briefly re naming the class, while it handles an exception traceback, I wanted to note that this implementation has no specific tie to tracebacks or exceptions - rather it supports the additional behavior of copying a certain string to the clipboard (it need not be called
self.tracebackortraceback).
@neiljp But I've inherited the NoticeView class and ensured that this version (ExceptionView) is only used for handling exceptions and copying the traceback. I didn't make any changes to the original class. Given this, should I still consider renaming it? If so, do you have any suggestions for a new name?
Thanks for the review @neiljp @Niloth-p :)
I've updated the original PR comment to include a table showing the visual changes before and after.
Regarding the code snippet to test this functionality, here's the approach I took (and shared with Niloth):
I went to boxes.py and raised my own ValueError when pressing "Esc" (GO_BACK) from the compose box. Then, I opened the compose box and pressed Esc to trigger the exception.
To test it, add the following code after the elif is_command_key("GO_BACK", key): line (801) in boxes.py:
import sys
try:
raise ValueError("This is a test exception")
except:
self.view.controller.raise_exception_in_main_thread(
sys.exc_info(), critical=False)
To clarify the difference between the traceback statements:
"".join(traceback.format_exception(*exc)) - complete traceback
File "/home/ubuntu/zulip-terminal/zulipterminal/ui_tools/boxes.py", line 804, in keypress
raise ValueError("This is a test exception")
ValueError: This is a test exception
"".join(traceback.format_exception_only(exc[0], exc[1])) - exception type and instance
ValueError: This is a test exception
@neiljp Thanks for the feedback, updated this PR 👍
@rsashank Thanks for the updates :+1:
I just pushed back here with the following changes:
- capitalized the Exception Popup (similar to Niloth's changes) in the help
- removed an additional default string parameter
- used a dynamic key for COPY_TRACEBACK (as per https://github.com/zulip/zulip-terminal/pull/1513#discussion_r1747842740)
I also have dropped the last commit, since it doesn't appear to work properly (eg. a recent update of key name(s) causes a crash) and we discussed previously that it might be something not to include, at least in this iteration.
I tested manually by raising an exception in the event loop try block, where the code is normally called.
I'll push the minor textual changes I had in mind separately, after merging this now 🎉