Skip to content

[py3.12] Missing distutils package causes hard to debug exception. #156

@dwt

Description

@dwt

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions