aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGertjan van den Burg <gertjanvandenburg@gmail.com>2020-04-04 22:38:58 +0100
committerGertjan van den Burg <gertjanvandenburg@gmail.com>2020-04-04 22:38:58 +0100
commit504180c138172d7c371a7e9ad984915ab048c64f (patch)
tree4f95fdff9f260c928bfbd2344dcc683a00ba0650
parentMerge branch 'bugfix/arXiv_stamp' (diff)
downloadpaper2remarkable-504180c138172d7c371a7e9ad984915ab048c64f.tar.gz
paper2remarkable-504180c138172d7c371a7e9ad984915ab048c64f.zip
Replace excepthook for nicer errors
I think that generally a traceback is too much info for an end-user, and the error message we provide can get lost in the noise. This commit disables the standard excepthook with its traceback, and replaces it with just the message of the exception. Using the debug flag enables the original traceback.
-rw-r--r--paper2remarkable/ui.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/paper2remarkable/ui.py b/paper2remarkable/ui.py
index bf57552..2fbf49f 100644
--- a/paper2remarkable/ui.py
+++ b/paper2remarkable/ui.py
@@ -169,8 +169,21 @@ def choose_provider(cli_input):
return provider, new_input, cookiejar
+def set_excepthook(debug):
+ sys_hook = sys.excepthook
+
+ def exception_handler(exception_type, value, traceback):
+ if debug:
+ sys_hook(exception_type, value, traceback)
+ else:
+ print(value, file=sys.stderr)
+
+ sys.excepthook = exception_handler
+
+
def main():
args = parse_args()
+ set_excepthook(args.debug)
if args.center and args.right:
exception("Can't center and right align at the same time!")