Hi there,
while packaging vpn-slice for nixpkgs, we noticed a harder than necessary to debug problem, because this exception handler here eats the backtrace and amkes it way harder to find why the code failed.
I would like to propose something like:
except Exception as e:
if self_test:
print('******************************************************************************************', file=stderr)
print('*** Self-test did not pass. Double-check that you are running as root (e.g. with sudo) ***', file=stderr)
print('******************************************************************************************', file=stderr)
raise SystemExit(*e.args) form e
That should usually be enough to retain the original backtrace, but won't work here because SystemExit does not print a stack trace by design.
A local alternative could be:
except Exception as e:
import traceback
traceback.print_exc()
if self_test:
print('******************************************************************************************', file=stderr)
print('*** Self-test did not pass. Double-check that you are running as root (e.g. with sudo) ***', file=stderr)
print('******************************************************************************************', file=stderr)
raise SystemExit(*e.args)
More work but better would be to not catch Exception (as that is too generic) and instead catch specific expected exceptions, so that unexpected ones like ImportError can be shown with backtrace by the interpreter and help debugging.
Hi there,
while packaging vpn-slice for nixpkgs, we noticed a harder than necessary to debug problem, because this exception handler here eats the backtrace and amkes it way harder to find why the code failed.
I would like to propose something like:
That should usually be enough to retain the original backtrace, but won't work here because
SystemExitdoes not print a stack trace by design.A local alternative could be:
More work but better would be to not catch Exception (as that is too generic) and instead catch specific expected exceptions, so that unexpected ones like
ImportErrorcan be shown with backtrace by the interpreter and help debugging.