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

Add depends_on path to error output #248

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/scippnexus/nxtransformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def parse_depends_on_chain(
chain.transformations[transform.name] = transform[()]
except KeyError as e:
warnings.warn(
UserWarning(f'depends_on chain references missing node {e}'), stacklevel=2
UserWarning(f'depends_on chain {depends_on} references missing node {e}'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No sure what this adds? I think the depends_on was already in the warning message as e?

Old error message: UserWarning: depends_on chain references missing node 'transform'
New error message: UserWarning: depends_on chain transform references missing node 'transform'

The KeyError is just the name of the missing entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a lucky example, what I'm interested in is which node is causing the problem, and I get a message like so:

WARNING root:fileloading_test.py:31 UserWarning: depends_on chain /entry/instrument/detector_panel_2/transformations/stageZ references missing node 'depends_on'

Run against 443503_00032754.hdf

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is complaining as the tests at

def test_compute_positions_warns_if_depends_on_is_dead_link(h5root):
instrument = snx.create_class(h5root, 'instrument', snx.NXinstrument)
detector = create_detector(instrument)
snx.create_field(detector, 'depends_on', sc.scalar('transform'))
root = make_group(h5root)
with pytest.warns(UserWarning, match='depends_on chain references missing node'):
loaded = root[()]
with pytest.warns(UserWarning, match='depends_on chain references missing node'):
snx.compute_positions(loaded)
also need to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran it locally like so UserWarning(f'depends_on chain references missing node {e} {depends_on}'), and that was good enough for me then although it doesn't read as nicely. If that makes it easier to do the matching though you could do that, in case you match multiple warnings using wildcards

Copy link
Member

@nvaytet nvaytet Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the match with match='depends_on chain .* references missing node' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, let's see if it works

stacklevel=2,
)
return None
return chain
Expand Down
4 changes: 2 additions & 2 deletions tests/nxtransformations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,9 @@ def test_compute_positions_warns_if_depends_on_is_dead_link(h5root):
detector = create_detector(instrument)
snx.create_field(detector, 'depends_on', sc.scalar('transform'))
root = make_group(h5root)
with pytest.warns(UserWarning, match='depends_on chain references missing node'):
with pytest.warns(UserWarning, match='depends_on chain .* references missing node'):
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
loaded = root[()]
with pytest.warns(UserWarning, match='depends_on chain references missing node'):
with pytest.warns(UserWarning, match='depends_on chain .* references missing node'):
ggoneiESS marked this conversation as resolved.
Show resolved Hide resolved
snx.compute_positions(loaded)


Expand Down
Loading