Skip to content

Commit 4a5a0fd

Browse files
committed
Add the UnknownCodecError
1 parent 5502dc8 commit 4a5a0fd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

numcodecs/errors.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
This module defines custom exceptions that are raised in the `numcodecs` codebase.
3+
"""
4+
5+
class UnknownCodecError(Exception):
6+
"""
7+
An exception that is raised when trying to receive a codec that has not been registered.
8+
9+
Parameters
10+
----------
11+
codec_id : str
12+
Codec identifier.
13+
"""
14+
15+
def __init__(self, codec_id: str):
16+
self.codec_id = codec_id
17+
super().__init__(f"codec not available: '{codec_id}'")

numcodecs/registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from importlib.metadata import EntryPoints, entry_points
66

77
from numcodecs.abc import Codec
8+
from numcodecs.errors import UnknownCodecError
89

910
logger = logging.getLogger("numcodecs")
1011
codec_registry: dict[str, Codec] = {}
@@ -50,7 +51,7 @@ def get_codec(config):
5051
register_codec(cls, codec_id=codec_id)
5152
if cls:
5253
return cls.from_config(config)
53-
raise ValueError(f'codec not available: {codec_id!r}')
54+
raise UnknownCodecError(f"{codec_id!r}")
5455

5556

5657
def register_codec(cls, codec_id=None):

0 commit comments

Comments
 (0)