Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123061
D4738.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D4738.diff
View Options
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
Details
Attached
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
Attached To
D4738: Trap and report exceptions in a unified way within the cli
Event Timeline
Log In to Comment