Improve reading error for selected plugins#377
Conversation
|
ok these tests are unexpectedly failing cause they just passed locally. I think I did something weird. Please hold... |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #377 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 37 37
Lines 2785 2794 +9
=========================================
+ Hits 2785 2794 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Ok this remaining error is totally not my fault, I will address in separate PR. Also this will probs break |
|
If you saw the original version, I was in the wrong env, naturally. |
| True, if the layer_data indicates an empty file, False otherwise | ||
| """ | ||
| return ( | ||
| isinstance(layer_data, list) |
There was a problem hiding this comment.
is it always list or can it be like a tuple?
There was a problem hiding this comment.
So I think technically speaking it could be a tuple, but this function was reproduced from napari, so it's what we've always used to validate the return type of readers. I'd say we keep it like this for now, and change it later if need be. Looking at the docs for readers, we always refer to a list also.
|
It might still be worth getting this PR in, but I'm not going to include it in v0.7.10 as it's going to potentially hold up napari/napari#8622 and I can't figure out how to easily test it until we merge napari/napari#8509 (lots of unrelated pydantic errors), which we can't do until we release v0.7.10. |
| # we don't return null layers if the user selected a plugin, | ||
| # so that we can raise a meaningful error | ||
| continue | ||
| return (layer_data, rdr) if return_reader else layer_data |
There was a problem hiding this comment.
Should we still check if layer_data isn't None/False before this return?
There was a problem hiding this comment.
I'm pushing this change, and adding a test to see if that is the behavior we want. I think that what you say makes sense
There was a problem hiding this comment.
I think this change is ok. Technically the reader should never be returning falsy things, but many probably do, so I think this is more defensive.
When a plugin is selected by the user to read a file, we want to raise specific error messages when that reader fails to read, for whatever reason.
Prior to this PR:
get_readerfunction returnedNone, the error message would say that the pluginreturned no datanull_layer_sentinel, no error would be surfaced innapari. I think this is a holdover from olden days when we would cascade readers, so we didn't want thenull_layer_sentinelto throw an error. I think there's probably good reason to remove thenull_layer_sentinelentirely, but that's a discussion for another day.With this PR:
"Reader {plugin_name!r} was selected to open {paths!r}, but refused the file."null_layer_sentinel, we get"Reader {plugin_name!r} was selected to open {paths!r}, but returned no data."As an aside, if a plugin is not selected, we get a semi-generic
"No readers returned data"but I think this is also ok as, from thenapariside, it's ~impossible for npe2 reading to get called without a plugin selected - either we use the preferred one, the user specifically selects one, or we explicitly pass the only one available.Note that this brings the
_is_null_layer_sentinelfunction tonpe2, and it previously lived innapari. I think this is ok, and if we're happy with this PR, we can update its usage innaparito import from here.Note also that this function checks specifically for a
list(same as with napari/#7851), not a container sequence, but I actually think this is also ok and maybe we should update our typing in other places to simply expect a list, since many other container sequences wouldn't be useful anyway: adictwould likely fail somewhere weirdly, asetwould lead to unexpected layer orderings... I guess a generator would be ok? But I don't think anyone is returning anything except a list.