diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-04-04 22:38:58 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2020-04-04 22:38:58 +0100 |
| commit | 504180c138172d7c371a7e9ad984915ab048c64f (patch) | |
| tree | 4f95fdff9f260c928bfbd2344dcc683a00ba0650 | |
| parent | Merge branch 'bugfix/arXiv_stamp' (diff) | |
| download | paper2remarkable-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.py | 13 |
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!") |
