Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 3 additions & 0 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ def __setitem__(self, key, value):
if not os.path.exists(dir_path):
try:
os.makedirs(dir_path)
except OSError:
if not os.path.isdir(dir_path):
raise KeyError(key)
except Exception:
raise KeyError(key)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm...so this except case doesn't catch it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The except Exception block was catching it before, but it was just throwing KeyError instead--so my code would still error out. The block that I added only raises KeyError if the folder doesn't exist already. This way, workers can go on with their business if the folder already exists.

Copy link
Member

Choose a reason for hiding this comment

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

Should we then drop the except Exception entirely and only use except OSError? It seems bad to mask other errors by raising KeyError instead.

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 good idea. I wasn't sure about that part so I left it, but I'm not sure what other exceptions you can even expect from os.makedirs. If you got OSError because of permissions or something else that prevented making the folder, then the block that I added would raise KeyError anyway.

Copy link
Member

@jakirkham jakirkham Feb 20, 2019

Choose a reason for hiding this comment

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

Good point. We can improve this a bit then by checking the errno of the OSError. Namely if we find e.errno == errno.EEXIST, then we know this is a FileExistsError. If it's any other errno, we can just re-raise the exception as is.

ref: https://docs.python.org/3/library/exceptions.html#FileExistsError
ref: https://docs.python.org/3/library/errno.html#errno.EEXIST

Copy link
Member

Choose a reason for hiding this comment

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

Have taken the liberty of pushing a commit to your branch using the errno bit. Please let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

I wasn't sure about that part so I left it...

That makes sense. Honestly this is an orthogonal issue. So we need not address it here. Will raise an issue to follow-up on this after.

Copy link
Member

Choose a reason for hiding this comment

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

Went ahead and dropped the generic exception case as it didn't seem to be covered. Happy to revisit if we figure out it was needed for some reason.


Expand Down
Binary file added zarr/tests/data/store.zip
Binary file not shown.
1 change: 1 addition & 0 deletions zarr/tests/data/store/foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar