Description
I want to preface this by saying that this would be a minor UX improvement. Not blocking at all!
Context
Zarr is extensible with custom codecs, e.g. imagecodecs
. Naturally, this can lead to situations where the environment in which a Zarr archive was written is not the same as the environment in which a Zarr archive is read. This can lead to missing codecs when trying to load data from a Zarr archive.
Description
If you try to access a Zarr array that uses a codec which is not registered locally, a generic ValueError
is thrown.
ValueError: codec not available: 'imagecodecs_jpeg2k'
In downstream libraries that use Zarr under the hood, this makes it harder to catch this specific error and to suggest an appropriate solution.
Instead, it would be great if a custom error is thrown that holds some additional information. For example
class InvalidCodecError(Exception):
"""Raised when an expected codec is not registered."""
def __init__(self, codec_name: str):
self.codec_name = codec_name
super().__init__(f"Codec not available: '{codec_name}'")
This would enable something like:
try:
arr = root["array"]
except InvalidCodecError as error:
if error.codec_name == "imagecodecs_jpeg2k":
raise RuntimeError("This Zarr archive requires `imagecodecs`, to install it use ...") from error