8000 Improve exception docs (#2624) · zarr-developers/zarr-python@c070940 · GitHub
[go: up one dir, main page]

Skip to content

Commit c070940

Browse files
authored
Improve exception docs (#2624)
1 parent a460fbc commit c070940

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/zarr/errors.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,41 @@
11
from typing import Any
22

3+
__all__ = [
4+
"BaseZarrError",
5+
"ContainsArrayAndGroupError",
6+
"ContainsArrayError",
7+
"ContainsGroupError",
8+
"MetadataValidationError",
9+
"NodeTypeValidationError",
10+
]
11+
12+
13+
class BaseZarrError(ValueError):
14+
"""
15+
Base error which all zarr errors are sub-classed from.
16+
"""
317

4-
class _BaseZarrError(ValueError):
518
_msg = ""
619

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

1023

11-
class ContainsGroupError(_BaseZarrError):
24+
class ContainsGroupError(BaseZarrError):
25+
"""Raised when a group already exists at a certain path."""
26+
1227
_msg = "A group exists in store {!r} at path {!r}."
1328

1429

15-
class ContainsArrayError(_BaseZarrError):
30+
class ContainsArrayError(BaseZarrError):
31+
"""Raised when an array already exists at a certain path."""
32+
1633
_msg = "An array exists in store {!r} at path {!r}."
1734

1835

19-
class ContainsArrayAndGroupError(_BaseZarrError):
36+
class ContainsArrayAndGroupError(BaseZarrError):
37+
"""Raised when both array and group metadata are found at the same path."""
38+
2039
_msg = (
2140
"Array and group metadata documents (.zarray and .zgroup) were both found in store "
2241
"{!r} at path {!r}. "
@@ -25,8 +44,8 @@ class ContainsArrayAndGroupError(_BaseZarrError):
2544
)
2645

2746

28-
class MetadataValidationError(_BaseZarrError):
29-
"""An exception raised when the Zarr metadata is invalid in some way"""
47+
class MetadataValidationError(BaseZarrError):
48+
"""Raised when the Zarr metadata is invalid in some way"""
3049

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

@@ -38,10 +57,3 @@ class NodeTypeValidationError(MetadataValidationError):
3857
This can be raised when the value is invalid or unexpected given the context,
3958
for example an 'array' node when we expected a 'group'.
4059
"""
41-
42-
43-
__all__ = [
44-
"ContainsArrayAndGroupError",
45-
"ContainsArrayError",
46-
"ContainsGroupError",
47-
]

0 commit comments

Comments
 (0)
0