Page MenuHomeSoftware Heritage

D4738.diff
No OneTemporary

D4738.diff

diff --git a/swh/deposit/cli/client.py b/swh/deposit/cli/client.py
--- a/swh/deposit/cli/client.py
+++ b/swh/deposit/cli/client.py
@@ -5,6 +5,7 @@
from __future__ import annotations
+from contextlib import contextmanager
from datetime import datetime, timezone
import logging
@@ -34,6 +35,23 @@
pass
+@contextmanager
+def trap_and_report_exceptions():
+ """Trap and report exceptions (InputError, MaintenanceError) in a unified way.
+
+ """
+ from swh.deposit.client import MaintenanceError
+
+ try:
+ yield
+ except InputError as e:
+ logger.error("Problem during parsing options: %s", e)
+ sys.exit(1)
+ except MaintenanceError as e:
+ logger.error(e)
+ sys.exit(1)
+
+
def generate_slug() -> str:
"""Generate a slug (sample purposes).
@@ -368,7 +386,7 @@
"""
import tempfile
- from swh.deposit.client import MaintenanceError, PublicApiDepositClient
+ from swh.deposit.client import PublicApiDepositClient
if archive_deposit or metadata_deposit:
warnings.warn(
@@ -383,7 +401,7 @@
client = PublicApiDepositClient(url=url, auth=(username, password))
with tempfile.TemporaryDirectory() as temp_dir:
- try:
+ with trap_and_report_exceptions():
logger.debug("Parsing cli options")
config = client_command_parse_input(
client,
@@ -401,12 +419,6 @@
author,
temp_dir,
)
- except InputError as e:
- logger.error("Problem during parsing options: %s", e)
- sys.exit(1)
- except MaintenanceError as e:
- logger.error(e)
- sys.exit(1)
if verbose:
logger.info("Parsed configuration: %s", config)
@@ -446,19 +458,13 @@
"""Deposit's status
"""
- from swh.deposit.client import MaintenanceError, PublicApiDepositClient
+ from swh.deposit.client import PublicApiDepositClient
url = _url(url)
logger.debug("Status deposit")
- try:
+ with trap_and_report_exceptions():
client = PublicApiDepositClient(url=url, auth=(username, password))
collection = _collection(client)
- except InputError as e:
- logger.error("Problem during parsing options: %s", e)
- sys.exit(1)
- except MaintenanceError as e:
- logger.error(e)
- sys.exit(1)
print_result(
client.deposit_status(collection=collection, deposit_id=deposit_id),

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 17, 6:44 PM (2 d, 17 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218364

Event Timeline