-
Notifications
You must be signed in to change notification settings - Fork 571
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 debug mode #1860
Changes from 32 commits
1bb0afa
1680d2f
29da6f3
8fd1e12
2c2cce4
ea5ca21
1d65eea
05f3114
ad660c5
8006ee6
a3e09ae
579da77
a7969d5
e1a73b8
b1846cc
f81a8c9
cb2fa8c
385a298
345b2db
4f89441
edba966
325b9fc
8cd428c
3a91963
26304f5
f6ad042
01cb484
4263069
a7ee43a
32720be
02eacba
7ba8db1
f0c29b4
2e358d9
34b0ec6
525908d
a0e1763
d12bcd3
cb866d6
32a7360
172eb0d
7ac646b
495f1e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,7 +18,8 @@ | |||||||||||||||||||||||||||
import datetime | ||||||||||||||||||||||||||||
import textwrap | ||||||||||||||||||||||||||||
import contextlib | ||||||||||||||||||||||||||||
from typing import Any, Set, Dict, List, Callable, Optional | ||||||||||||||||||||||||||||
from types import TracebackType | ||||||||||||||||||||||||||||
from typing import Any, Set, Dict, List, Type, Union, Callable, Optional | ||||||||||||||||||||||||||||
from pathlib import Path | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import halo | ||||||||||||||||||||||||||||
|
@@ -112,6 +113,7 @@ | |||||||||||||||||||||||||||
E_MISSING_CAPE_STATIC_ANALYSIS = 21 | ||||||||||||||||||||||||||||
E_MISSING_CAPE_DYNAMIC_ANALYSIS = 22 | ||||||||||||||||||||||||||||
E_EMPTY_REPORT = 23 | ||||||||||||||||||||||||||||
E_UNHANDLED = 24 | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
logger = logging.getLogger("capa") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -978,6 +980,26 @@ def handle_common_args(args): | |||||||||||||||||||||||||||
args.signatures = sigs_path | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def simple_message_exception_handler( | ||||||||||||||||||||||||||||
exctype: Union[type[BaseException], Type[BaseException]], | ||||||||||||||||||||||||||||
value: BaseException, | ||||||||||||||||||||||||||||
traceback: TracebackType, | ||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||
if not in debug mode, prints helpful message on unhandled exceptions | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
args: | ||||||||||||||||||||||||||||
# TODO(aaronatp): Once capa drops support for Python 3.8, move this to the type annotation in the function parameters | ||||||||||||||||||||||||||||
exctype (type[BaseException]): exception class | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this still accurate or can it be removed? |
||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
print( | ||||||||||||||||||||||||||||
f"Unexpected exception raised: {exctype}. Please run capa in debug mode (-d/--debug) " | ||||||||||||||||||||||||||||
+ "to see the stack trace. Please also report your issue on the capa GitHub page so we " | ||||||||||||||||||||||||||||
+ "can improve the code! (https://github.com/mandiant/capa/issues)" | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think of this to also handle CTRL-C (and not say unhandled exception there) |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def main(argv: Optional[List[str]] = None): | ||||||||||||||||||||||||||||
if sys.version_info < (3, 8): | ||||||||||||||||||||||||||||
raise UnsupportedRuntimeError("This version of capa can only be used with Python 3.8+") | ||||||||||||||||||||||||||||
|
@@ -1020,6 +1042,8 @@ def main(argv: Optional[List[str]] = None): | |||||||||||||||||||||||||||
install_common_args(parser, {"sample", "format", "backend", "os", "signatures", "rules", "tag"}) | ||||||||||||||||||||||||||||
parser.add_argument("-j", "--json", action="store_true", help="emit JSON instead of text") | ||||||||||||||||||||||||||||
args = parser.parse_args(args=argv) | ||||||||||||||||||||||||||||
if not args.debug: | ||||||||||||||||||||||||||||
sys.excepthook = simple_message_exception_handler | ||||||||||||||||||||||||||||
ret = handle_common_args(args) | ||||||||||||||||||||||||||||
if ret is not None and ret != 0: | ||||||||||||||||||||||||||||
return ret | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.