Skip to content

Commit d581b4e

Browse files
committed
Consistent version error
1 parent 43484a1 commit d581b4e

File tree

5 files changed

+6
-949
lines changed

5 files changed

+6
-949
lines changed

src/zarr/core/array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
from zarr.core.metadata.v2 import ArrayV2Metadata
6868
from zarr.core.metadata.v3 import ArrayV3Metadata
6969
from zarr.core.sync import collect_aiterator, sync
70+
from zarr.errors import MetadataValidationError
7071
from zarr.registry import get_pipeline_class
7172
from zarr.storage import StoreLike, make_store_path
7273
from zarr.storage.common import StorePath, ensure_no_existing_node
@@ -144,7 +145,7 @@ async def get_array_metadata(
144145
else:
145146
zarr_format = 2
146147
else:
147-
raise ValueError(f"unexpected zarr_format: {zarr_format}")
148+
raise MetadataValidationError("zarr_format", "2, 3, or None", zarr_format)
148149

149150
metadata_dict: dict[str, Any]
150151
if zarr_format == 2:

src/zarr/core/group.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030
from zarr.core.config import config
3131
from zarr.core.sync import SyncMixin, sync
32+
from zarr.errors import MetadataValidationError
3233
from zarr.storage import StoreLike, make_store_path
3334
from zarr.storage.common import StorePath, ensure_no_existing_node
3435

@@ -196,7 +197,7 @@ async def open(
196197
else:
197198
zarr_format = 2
198199
else:
199-
raise ValueError(f"unexpected zarr_format: {zarr_format}")
200+
raise MetadataValidationError("zarr_format", "2, 3, or None", zarr_format)
200201

201202
if zarr_format == 2:
202203
# V2 groups are comprised of a .zgroup and .zattrs objects

src/zarr/core/metadata/v3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
def parse_zarr_format(data: object) -> Literal[3]:
3939
if data == 3:
4040
return 3
41-
raise MetadataValidationError(3, data)
41+
raise MetadataValidationError("zarr_format", 3, data)
4242

4343

4444
def parse_node_type_array(data: object) -> Literal["array"]:

src/zarr/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ContainsArrayAndGroupError(_BaseZarrError):
2828
class MetadataValidationError(_BaseZarrError):
2929
"""An exception raised when the Zarr metadata is invalid in some way"""
3030

31-
_msg = "Invalid value. Expected '{}'. Got '{}'."
31+
_msg = "Invalid value for '{}'. Expected '{}'. Got '{}'."
3232

3333

3434
class NodeTypeValidationError(MetadataValidationError):

0 commit comments

Comments
 (0)