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

CLI flag for run command to raise exceptions to the caller #1394

Merged

Conversation

mariuspod
Copy link
Contributor

What I did

I've added a -r cli flag for the brownie run cli command which raises any exceptions to the caller instead of doing a system exit. I've noticed a system exit breaks the auto-capturing of exceptions with sentry because the excepthooks are not triggered at all.

With this addition I could verify that running a brownie script with the current sentry_sdk works and automatically captures any unhandled exceptions like expected.

How I did it

I've just modified the except blocks slightly to check for the flag and preserve the existing logic if it's not present.

How to verify it

$ echo "1/0" > scripts/fail.py
$ brownie run fail -r
Traceback (most recent call last):
  File "/usr/local/bin/brownie", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/brownie/_cli/__main__.py", line 70, in main
    raise e
  File "/usr/local/lib/python3.9/site-packages/brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "/usr/local/lib/python3.9/site-packages/brownie/_cli/run.py", line 60, in main
    raise e
  File "/usr/local/lib/python3.9/site-packages/brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "/usr/local/lib/python3.9/site-packages/brownie/project/scripts.py", line 53, in run
    module = _import_from_path(script)
  File "/usr/local/lib/python3.9/site-packages/brownie/project/scripts.py", line 149, in _import_from_path
    _import_cache[import_str] = importlib.import_module(import_str)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/app/scripts/fail.py", line 1, in <module>
    1/0
ZeroDivisionError: division by zero

Checklist

  • I have confirmed that my PR passes all linting checks
  • I have included test cases
  • I have updated the documentation
  • I have added an entry to the changelog

@iamdefinitelyahuman iamdefinitelyahuman merged commit 202c43d into eth-brownie:master Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants