Skip to content

Commit

Permalink
refactor to use less generic error UnsupportedArchiveFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Neagu committed Dec 13, 2024
1 parent 7f3e41e commit be58b0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/service-library/src/servicelib/archiving_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class ArchiveError(Exception):
"""


class UnsupportedArchiveFormat(Exception):
pass


def _human_readable_size(size, decimal_places=3):
human_readable_file_size = float(size)
unit = "B"
Expand Down Expand Up @@ -260,6 +264,10 @@ async def unarchive_dir(
f"Failed unarchiving {archive_to_extract} -> {destination_folder} due to {type(err)}."
f"Details: {err}"
)
# maybe write unsupported error format here instead of all this to be able to still raise in case of error
if isinstance(err, NotImplementedError):
raise UnsupportedArchiveFormat(msg) from err

raise ArchiveError(msg) from err

# NOTE: extracted_paths includes all tree leafs, which might include files and empty folders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from models_library.services_types import ServicePortKey
from pydantic import ByteSize
from servicelib.archiving_utils import (
ArchiveError,
PrunableFolder,
UnsupportedArchiveFormat,
archive_dir,
unarchive_dir,
)
Expand Down Expand Up @@ -307,7 +307,7 @@ async def _get_data_from_port(
dest_folder.prune(exclude=unarchived)

_logger.debug("all unzipped in %s", final_path)
except ArchiveError:
except UnsupportedArchiveFormat:
_logger.warning(
"Could not extract archive '%s' to '%s' moving it to: '%s'",
downloaded_file,
Expand Down

0 comments on commit be58b0c

Please sign in to comment.