-
Notifications
You must be signed in to change notification settings - Fork 65
Open
Description
Hi! I have another suggestion for exception handling. I ran into this:
AttributeError Traceback (most recent call last)
Cell In[3], line 5
1 path = "/wrong_path_by_mistake.ome.zarr"
3 p = parse_url(path)
----> 5 reader = Reader(p)
7 nodes = list(reader())
8 image_node = nodes[0]
File ~/repos/ome-zarr-py/ome_zarr/reader.py:569, in Reader.__init__(self, zarr)
568 def __init__(self, zarr: ZarrLocation) -> None:
--> 569 assert zarr.exists()
570 self.zarr = zarr
571 self.seen: list[ZarrLocation] = [zarr]
AttributeError: 'NoneType' object has no attribute 'exists'I was wondering why the zarr object is None, but the real issue was that the path I fed in does not exist because of a typo. It would be useful to instead handle whether the path is valid earlier.
By the way, somewhat related an exception should be raised/handled rather than using an assert. As far as I know the standard practice is to use assert only in tests (there are a few reasons, one of them is that there are interpreter options that disable assertions).
Happy to do a PR but thought I'd get your input first.
Metadata
Metadata
Assignees
Labels
No labels