cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

The option to only apply the stackprinter styles to certain exceptions (Alternatively, a whitelist/blacklist system) #67

Open AbdelRahmanRahal opened 11 months ago

AbdelRahmanRahal commented 11 months ago

As the title suggests, it would be great if we were able to add the stackprinter styles to only a select exception classes.

I came across this idea while developing a module. I wanted the error messages for my module to be prettier, but I didn't want any other error messages to be affected. If I use stackprinter within my module, I essentially force the user to also have its styles for all other exceptions including the ones within their own program, or at least that's what I experienced while testing.

A way to implement this could be by specifying a list of exception classes to whitelist or blacklist (but never both):

stackprinter.set_excepthook(
    style='darkbg2',
    whitelist=[
        TypeError,
        CustomException1,
        CustomException2
    ]
)