Skip to content
Merged
Changes from all 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
38 changes: 25 additions & 13 deletions src/zarr/errors.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
from typing import Any

__all__ = [
"BaseZarrError",
"ContainsArrayAndGroupError",
"ContainsArrayError",
"ContainsGroupError",
"MetadataValidationError",
"NodeTypeValidationError",
]


class BaseZarrError(ValueError):
"""
Base error which all zarr errors are sub-classed from.
"""

class _BaseZarrError(ValueError):
_msg = ""

def __init__(self, *args: Any) -> None:
super().__init__(self._msg.format(*args))


class ContainsGroupError(_BaseZarrError):
class ContainsGroupError(BaseZarrError):
"""Raised when a group already exists at a certain path."""

_msg = "A group exists in store {!r} at path {!r}."


class ContainsArrayError(_BaseZarrError):
class ContainsArrayError(BaseZarrError):
"""Raised when an array already exists at a certain path."""

_msg = "An array exists in store {!r} at path {!r}."


class ContainsArrayAndGroupError(_BaseZarrError):
class ContainsArrayAndGroupError(BaseZarrError):
"""Raised when both array and group metadata are found at the same path."""

_msg = (
"Array and group metadata documents (.zarray and .zgroup) were both found in store "
"{!r} at path {!r}. "
Expand All @@ -25,8 +44,8 @@ class ContainsArrayAndGroupError(_BaseZarrError):
)


class MetadataValidationError(_BaseZarrError):
"""An exception raised when the Zarr metadata is invalid in some way"""
class MetadataValidationError(BaseZarrError):
"""Raised when the Zarr metadata is invalid in some way"""

_msg = "Invalid value for '{}'. Expected '{}'. Got '{}'."

Expand All @@ -38,10 +57,3 @@ class NodeTypeValidationError(MetadataValidationError):
This can be raised when the value is invalid or unexpected given the context,
for example an 'array' node when we expected a 'group'.
"""


__all__ = [
"ContainsArrayAndGroupError",
"ContainsArrayError",
"ContainsGroupError",
]
Loading