Skip to content

Commit 5e81b1e

Browse files
committed
add missing exceptions
1 parent 630897b commit 5e81b1e

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

src/zarr/errors.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing_extensions import deprecated
22

33
__all__ = [
44
"BaseZarrError",
@@ -12,42 +12,42 @@
1212

1313
class BaseZarrError(ValueError):
1414
"""
15-
Base error which all zarr errors are sub-classed from.
15+
Base class for Zarr errors.
1616
"""
1717

18-
_msg = ""
19-
20-
def __init__(self, *args: Any) -> None:
21-
super().__init__(self._msg.format(*args))
22-
2318

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

27-
_msg = "A group exists in store {!r} at path {!r}."
28-
2922

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

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

27+
class ArrayNotFoundError(BaseZarrError):
28+
"""Raised when an array does not exist at a certain path."""
3529

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

39-
_msg = (
40-
"Array and group metadata documents (.zarray and .zgroup) were both found in store "
41-
"{!r} at path {!r}. "
42-
"Only one of these files may be present in a given directory / prefix. "
43-
"Remove the .zarray file, or the .zgroup file, or both."
44-
)
31+
class GroupNotFoundError(BaseZarrError):
32+
"""Raised when a group does not exist at a certain path."""
4533

4634

47-
class MetadataValidationError(BaseZarrError):
48-
"""Raised when the Zarr metadata is invalid in some way"""
35+
@deprecated("Use NodeNotFoundError instead.", category=None)
36+
class PathNotFoundError(BaseZarrError):
37+
# Backwards compatibility with v2. Superseded by NodeNotFoundError.
38+
...
39+
40+
41+
class NodeNotFoundError(PathNotFoundError):
42+
"""Raised when an array or group does not exist at a certain path."""
43+
4944

50-
_msg = "Invalid value for '{}'. Expected '{}'. Got '{}'."
45+
class ContainsArrayAndGroupError(BaseZarrError):
46+
"""Raised when both array and group metadata are found at the same path. Zarr V2 only."""
47+
48+
49+
class MetadataValidationError(BaseZarrError):
50+
"""Raised when a Zarr metadata document is invalid"""
5151

5252

5353
class NodeTypeValidationError(MetadataValidationError):
@@ -57,3 +57,9 @@ class NodeTypeValidationError(MetadataValidationError):
5757
This can be raised when the value is invalid or unexpected given the context,
5858
for example an 'array' node when we expected a 'group'.
5959
"""
60+
61+
62+
class ReadOnlyError(PermissionError, BaseZarrError):
63+
"""
64+
Exception for when a mutation is attempted on an immutable resource.
65+
"""

0 commit comments

Comments
 (0)