Skip to content

Commit

Permalink
fix: Hide irrelevant stacks during exc raise
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindsouza committed May 26, 2023
1 parent a1d2c52 commit 8175239
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def cli():
_opts = [x.opts + x.secondary_opts for x in bench_command.params]
opts = {item for sublist in _opts for item in sublist}

setup_exception_handler()

# handle usages like `--use-feature='feat-x'` and `--use-feature 'feat-x'`
if cmd_from_sys and cmd_from_sys.split("=", 1)[0].strip() in opts:
bench_command()
Expand Down Expand Up @@ -240,3 +242,17 @@ def _chdir(*args, **kwargs):
return f(*args, **kwargs)

os.chdir = _chdir


def setup_exception_handler():
from traceback import format_exception

def handle_exception(exc_type, exc_info, tb):
print("".join(generate_exc(exc_type, exc_info, tb)))

def generate_exc(exc_type, exc_info, tb):
for t in format_exception(exc_type, exc_info, tb):
if "/click/" not in t:
yield t

sys.excepthook = handle_exception

0 comments on commit 8175239

Please sign in to comment.