Skip to content

Commit 0814982

Browse files
authored
Raise error for Dataset.open() if dataset is not found. (#1246)
* Raise error for Dataset.open() if dataset is not found. * Update changelog. * Move path validation to Dataset.open()
1 parent 056976f commit 0814982

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

webknossos/Changelog.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
1919
### Changed
2020

2121
### Fixed
22+
- Fixed a misleading error message when Dataset.open() can't find a valid dataset. [#1246](https://github.com/scalableminds/webknossos-libs/pull/1246)
2223

2324

2425
## [0.16.6](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.16.6) - 2025-02-03
@@ -39,7 +40,6 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
3940
- Fixed a bug with loading metadata lists. [#1247](https://github.com/scalableminds/webknossos-libs/pull/1247)
4041

4142

42-
4343
## [0.16.4](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.16.4) - 2025-01-23
4444
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.16.3...v0.16.4)
4545

@@ -70,7 +70,6 @@ For upgrade instructions, please check the respective _Breaking Changes_ section
7070
- Fixed an issue when shallow copying datasets with a remote mag. [#1224](https://github.com/scalableminds/webknossos-libs/pull/1224)
7171

7272

73-
7473
## [0.16.2](https://github.com/scalableminds/webknossos-libs/releases/tag/v0.16.2) - 2024-12-18
7574
[Commits](https://github.com/scalableminds/webknossos-libs/compare/v0.16.1...v0.16.2)
7675

webknossos/tests/dataset/test_dataset.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,3 +2802,8 @@ def test_remote_dataset_urls() -> None:
28022802
f"http://localhost:9000/datasets/l4_sample-{dataset_id}/view#2786,4326,1816,0,3"
28032803
)
28042804
assert ds6.url == ds.url
2805+
2806+
2807+
def test_dataset_open_wrong_path() -> None:
2808+
with pytest.raises(FileNotFoundError):
2809+
Dataset.open("wrong_path")

webknossos/webknossos/dataset/dataset.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,16 @@ def open(cls, dataset_path: Union[str, PathLike]) -> "Dataset":
467467
468468
The `dataset_path` refers to the top level directory of the dataset (excluding layer or magnification names).
469469
"""
470-
return cls(
471-
dataset_path,
472-
voxel_size_with_unit=_UNSPECIFIED_SCALE_FROM_OPEN,
473-
exist_ok=True,
470+
if (
471+
path := strip_trailing_slash(UPath(dataset_path)) / PROPERTIES_FILE_NAME
472+
).exists():
473+
return cls(
474+
dataset_path,
475+
voxel_size_with_unit=_UNSPECIFIED_SCALE_FROM_OPEN,
476+
exist_ok=True,
477+
)
478+
raise FileNotFoundError(
479+
f"Could not find a valid `datasource-properties.json` file at {path}."
474480
)
475481

476482
@classmethod

0 commit comments

Comments
 (0)