Skip to content

Commit 33c0f8e

Browse files
authored
fix: Reraise exceptions in CLI-mode if run in debugger (#225)
## Description Many exceptions raised by `anemoi-datasets` are of type `ValueError`. Thus they are caught by `cli_main` and converted to a more user-friendly error. While this might increase the user experience, it prevents the use of Python debuggers. ## What problem does this change solve? Enable the use of debuggers to debug cli runs. E.g. `ipdb3 $(which anemoi-datasets) create ...` ## What issue or task does this change relate to? ## Additional notes ## ***As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/*** By opening this pull request, I affirm that all authors agree to the [Contributor License Agreement.](https://github.com/ecmwf/codex/blob/main/Legal/contributor_license_agreement.md)
1 parent 30b2d74 commit 33c0f8e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/anemoi/utils/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,13 @@ def cli_main(
265265
else:
266266
cmd.run(args)
267267
except ValueError as e:
268-
269268
if test_arguments:
270269
raise
271270

271+
if sys.excepthook is not sys.__excepthook__:
272+
# re-raise exception if non-default excepthook is set (e.g. in pdb)
273+
raise
274+
272275
traceback.print_exc()
273276
LOG.error("\n💣 %s", str(e).lstrip())
274277
LOG.error("💣 Exiting")

0 commit comments

Comments
 (0)