Skip to content

Commit

Permalink
Document exceptions raised by formatter V2
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 10, 2024
1 parent 27c5986 commit baf5683
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions python/lsst/daf/butler/_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,14 @@ def write(
A cache manager to use to allow a formatter to cache the written
file.
Raises
------
FormatterNotImplementedError
Raised if the formatter subclass has not implemented
`write_local_file` and `to_bytes` was not called.
Exception
Raised if there is an error serializing the dataset to disk.
Notes
-----
The intent is for subclasses to implement either `to_bytes` or
Expand Down Expand Up @@ -905,6 +913,12 @@ def write_direct(
written : `bool`
Flag to indicate whether the direct write did happen.
Raises
------
Exception
Raised if there was a failure from serializing to bytes that
was not `FormatterNotImplementedError`.
Notes
-----
This method will call `to_bytes` to serialize the in-memory dataset
Expand Down Expand Up @@ -963,6 +977,14 @@ def write_locally_then_move(
cache_manager : `AbstractDatastoreCacheManager`
A cache manager to use to allow a formatter to cache the written
file.
Raises
------
FormatterNotImplementedError
Raised if the formatter subclass has not implemented
`write_local_file`.
Exception
Raised if there is an error serializing the dataset to disk.
"""
cache_manager = self._ensure_cache(cache_manager)

Expand Down Expand Up @@ -1016,6 +1038,12 @@ def write_local_file(self, in_memory_dataset: Any, uri: ResourcePath) -> None:
-----
By default this method will attempt to call `to_bytes` and then
write these bytes to the file.
Raises
------
FormatterNotImplementedError
Raised if the formatter subclass has not implemented this method
or has failed to implement the `to_bytes` method.
"""
log.debug("Writing bytes directly to %s", uri)
uri.write(self.to_bytes(in_memory_dataset))
Expand All @@ -1033,6 +1061,12 @@ def to_bytes(self, in_memory_dataset: Any) -> bytes:
-------
serialized_dataset : `bytes`
Bytes representing the serialized dataset.
Raises
------
FormatterNotImplementedError
Raised if the formatter has not implemented the method. This will
not cause a problem if `write_local_file` has been implemented.
"""
raise FormatterNotImplementedError(

Check warning on line 1071 in python/lsst/daf/butler/_formatter.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/daf/butler/_formatter.py#L1071

Added line #L1071 was not covered by tests
f"This formatter can not convert {get_full_type_name(in_memory_dataset)} directly to bytes."
Expand Down

0 comments on commit baf5683

Please sign in to comment.