Repository navigation
fix(storage): raise a clear error in FsspecStore.from_url when the local directory does not exist - #4683
fix(storage): raise a clear error in FsspecStore.from_url when the local directory does not exist#46831915rising wants to merge 2 commits into
Conversation
|
i don't think we want to make automatic directory creation the default. |
|
Fair point. Silently creating directories can mask a mistyped path, and the default should not do that. The bug in #2808 is that the failure surfaces as a FileNotFoundError on the first write, far from the actual cause. Would you prefer from_url to raise a clear error at creation time when the local directory does not exist? I can rework this PR to do that instead. |
|
yes, I think a clearer error message that directs people to change the relevant fsspec options would be a great addition |
…cal directory does not exist
|
Reworked along the lines you suggested. |
Summary
Fixes #2808.
FsspecStore.from_url("file://.../new.zarr")failed on the first write withFileNotFoundError: .../new.zarr/zarr.json. The local filesystem is synchronous, so it gets wrapped, and it does not create directories on write unlessauto_mkdiris set. A plain local path works because LocalStore creates parent directories itself.Reworked following the feedback in this thread: instead of defaulting
auto_mkdirto True,from_urlnow raises a clearFileNotFoundErrorat creation time when a local URL (scheme missing,file, orlocal) points at a directory that does not exist and the caller has not enabledauto_mkdir. The message names the missing directory and directs the caller to create it first or passstorage_options={'auto_mkdir': True}. Nothing is created silently. Read-only stores are exempt, since they never write. Filesystems the caller builds themselves are untouched, so an explicitauto_mkdir=Falsefilesystem passed as a mapper still behaves as before, which an existing test covers.Tests:
tests/test_store/test_fsspec.pywas 101 passed, 17 skipped on unmodified main and is 102 passed, 17 skipped with this change. The regression test now asserts the creation-time error and its message, that the same path works withauto_mkdirset, and that a read-only store at a missing path does not raise. It fails on unmodified code. This PR was prepared with AI assistance; I reviewed and tested every line.Author attestation
TODO
docs/user-guide/*.mdchanges/