Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only show stack trace in dev mode #1515

Closed
williballenthin opened this issue Jun 4, 2023 · 4 comments
Closed

only show stack trace in dev mode #1515

williballenthin opened this issue Jun 4, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@williballenthin
Copy link
Collaborator

ensure that we only show a stack trace when users might want to (such as developers). otherwise provide a last line of defense exception handler to suggest what users can do.

https://www.bitecode.dev/p/why-and-how-to-hide-the-python-stack

@aaronatp
Copy link
Contributor

Hi @williballenthin I'd like to contribute to this issue. Thank you for linking this article! I have read it and it is very helpful.

As the article suggests, a callback could show the stack trace if sys.flags.dev_mode is True or print another message if it is false. Do you think something like the following would work here? I was also thinking about linking the capa Issues page and asking users to report any unexpected exceptions - is this potentially a good idea?

import sys

SHOW_STACK_TRACE = sys.flags.dev_mode

def last_resort_exception_handler(exctype, value, traceback):   
    if SHOW_STACK_TRACE:
        sys.__excepthook__(exctype, value, traceback)
    else:
        print(f"Unexpected exception raised: {exctype}. Please run capa in Python development mode "
            to see the stack trace (https://docs.python.org/3/library/devmode.html#devmode)")

sys.excepthook = last_resort_exception_handler

@williballenthin
Copy link
Collaborator Author

I think your idea is generally great. Lets try this out and see how it improves user experience.

One thought: lets use the --debug flag passed via CLI versus dev_mode. That's because "It should not be more verbose than the default if the code is correct".

parser.add_argument("-d", "--debug", action="store_true", help="enable debugging output on STDERR")

Please go ahead and open a PR and we can review it together.

@williballenthin williballenthin added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Nov 17, 2023
@aaronatp
Copy link
Contributor

@williballenthin awesome thank you! What you are saying about the --debug flag makes sense. I'll make that adjustment and open a PR!

@mr-tz
Copy link
Collaborator

mr-tz commented Dec 8, 2023

closed via #1860

@mr-tz mr-tz closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants