Skip to content

Commit

Permalink
Improve exception docs (#2624)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby authored Jan 3, 2025
1 parent a460fbc commit c070940
Showing 1 changed file with 25 additions and 13 deletions.
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",
]

0 comments on commit c070940

Please sign in to comment.