Skip to content

Commit 198a959

Browse files
authored
Merge pull request #266 from will-moore/remote_exception_handling
Don't handle exception in Multiscales init()
2 parents 9540832 + 7b56cb7 commit 198a959

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

ome_zarr/data.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def create_zarr(
104104
label_name: str = "coins",
105105
fmt: Format = CurrentFormat(),
106106
chunks: Union[Tuple, List] = None,
107-
) -> None:
107+
) -> zarr.Group:
108108
"""Generate a synthetic image pyramid with labels."""
109109
pyramid, labels = method()
110110

@@ -192,3 +192,5 @@ def create_zarr(
192192
"properties": properties,
193193
"source": {"image": "../../"},
194194
}
195+
196+
return grp

ome_zarr/reader.py

+18-22
Original file line numberDiff line numberDiff line change
@@ -277,28 +277,24 @@ def matches(zarr: ZarrLocation) -> bool:
277277
def __init__(self, node: Node) -> None:
278278
super().__init__(node)
279279

280-
try:
281-
multiscales = self.lookup("multiscales", [])
282-
version = multiscales[0].get(
283-
"version", "0.1"
284-
) # should this be matched with Format.version?
285-
datasets = multiscales[0]["datasets"]
286-
axes = multiscales[0].get("axes")
287-
fmt = format_from_version(version)
288-
# Raises ValueError if not valid
289-
axes_obj = Axes(axes, fmt)
290-
node.metadata["axes"] = axes_obj.to_list()
291-
# This will get overwritten by 'omero' metadata if present
292-
node.metadata["name"] = multiscales[0].get("name")
293-
paths = [d["path"] for d in datasets]
294-
self.datasets: List[str] = paths
295-
transformations = [d.get("coordinateTransformations") for d in datasets]
296-
if any(trans is not None for trans in transformations):
297-
node.metadata["coordinateTransformations"] = transformations
298-
LOGGER.info("datasets %s", datasets)
299-
except Exception:
300-
LOGGER.exception("Failed to parse multiscale metadata")
301-
return # EARLY EXIT
280+
multiscales = self.lookup("multiscales", [])
281+
version = multiscales[0].get(
282+
"version", "0.1"
283+
) # should this be matched with Format.version?
284+
datasets = multiscales[0]["datasets"]
285+
axes = multiscales[0].get("axes")
286+
fmt = format_from_version(version)
287+
# Raises ValueError if not valid
288+
axes_obj = Axes(axes, fmt)
289+
node.metadata["axes"] = axes_obj.to_list()
290+
# This will get overwritten by 'omero' metadata if present
291+
node.metadata["name"] = multiscales[0].get("name")
292+
paths = [d["path"] for d in datasets]
293+
self.datasets: List[str] = paths
294+
transformations = [d.get("coordinateTransformations") for d in datasets]
295+
if any(trans is not None for trans in transformations):
296+
node.metadata["coordinateTransformations"] = transformations
297+
LOGGER.info("datasets %s", datasets)
302298

303299
for resolution in self.datasets:
304300
data: da.core.Array = self.array(resolution, version)

tests/test_reader.py

+18
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ def test_label(self):
3333
assert len(list(reader())) == 3
3434

3535

36+
class TestInvalid:
37+
@pytest.fixture(autouse=True)
38+
def initdir(self, tmpdir):
39+
self.path = tmpdir.mkdir("data")
40+
41+
def test_invalid_version(self):
42+
grp = create_zarr(str(self.path))
43+
# update version to something invalid
44+
attrs = grp.attrs.asdict()
45+
attrs["multiscales"][0]["version"] = "invalid"
46+
grp.attrs.put(attrs)
47+
# should raise exception
48+
with pytest.raises(ValueError) as exe:
49+
reader = Reader(parse_url(str(self.path)))
50+
assert len(list(reader())) == 2
51+
assert str(exe.value) == "Version invalid not recognized"
52+
53+
3654
class TestHCSReader:
3755
@pytest.fixture(autouse=True)
3856
def initdir(self, tmpdir):

0 commit comments

Comments
 (0)