This repository has been archived by the owner on Oct 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Add path to error message in map_over_subtree #264
Merged
TomNicholas
merged 20 commits into
xarray-contrib:main
from
TomNicholas:error_context_map_over_subtree
Oct 24, 2023
Merged
Add path to error message in map_over_subtree #264
TomNicholas
merged 20 commits into
xarray-contrib:main
from
TomNicholas:error_context_map_over_subtree
Oct 24, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TomNicholas
commented
Oct 23, 2023
datatree/mapping.py
Outdated
return func(*args, **kwargs) | ||
except Exception as e: | ||
# Add the context information to the error message | ||
e.add_note(f"Raised whilst mapping function over node with path {path}") |
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.
Adding notes to exceptions is a new feature in python 3.11.
Perhaps we should wait before merging this? If I understand xarray's deprecation policy correctly then 3.11 will only be the minimum supported version of python 24 months after 3.11 is released, which is 12 months from now...
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.
you could use a helper for this:
def add_note(err: BaseException, msg: str) -> None:
# TODO: remove once python 3.10 can be dropped
if sys.version_info < (3, 11):
err.__notes__ = getattr(err, "__notes__", []) + [msg]
else:
err.add_note(msg)
…a info in the error message
for more information, see https://pre-commit.ci
…omNicholas/datatree into error_context_map_over_subtree
for more information, see https://pre-commit.ci
…omNicholas/datatree into error_context_map_over_subtree
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…omNicholas/datatree into error_context_map_over_subtree
flamingbear
pushed a commit
to flamingbear/rewritten-datatree
that referenced
this pull request
Jan 19, 2024
…#264 * test * implementation * formatting * add version check, if not using 3.11 then you just won't get the extra info in the error message * whatsnew * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use better helper function * xfail test, because this does actually work... --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
map_over_subtree
#190, and would have helped with Error in datatree.DataTree.sel when attributes are set #262pre-commit run --all-files
New functions/methods are listed inapi.rst
docs/source/whats-new.rst