Skip to content

Commit

Permalink
feat(cli): change user output when handling errors (DEV-3067) (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann committed Dec 6, 2023
1 parent 692ad40 commit 71a1737
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/dsp_tools/cli.py
Expand Up @@ -27,7 +27,7 @@
from dsp_tools.commands.template import generate_template_repo
from dsp_tools.commands.xmlupload.upload_config import DiagnosticsConfig, UploadConfig
from dsp_tools.commands.xmlupload.xmlupload import xmlupload
from dsp_tools.models.exceptions import UserError
from dsp_tools.models.exceptions import BaseError, InternalError, UserError
from dsp_tools.utils.create_logger import get_logger
from dsp_tools.utils.shared import validate_xml_against_schema

Expand Down Expand Up @@ -581,6 +581,12 @@ def run(args: list[str]) -> None:
Args:
args: a list of arguments passed by the user from the command line,
excluding the leading "dsp-tools" command.
Raises:
UserError: if user input was wrong
InputError: if user input was wrong
InternalError: if the user cannot fix it
RetryError: if the problem may disappear when trying again later
"""
default_dsp_api_url = "http://0.0.0.0:3333"
default_sipi_url = "http://0.0.0.0:1024"
Expand All @@ -605,11 +611,14 @@ def run(args: list[str]) -> None:
default_sipi_url=default_sipi_url,
)
success = _call_requested_action(parsed_arguments)
except UserError as err:
logger.error(f"Terminate because of this UserError: {err.message}")
except BaseError as err:
logger.error(err)
print("\nThe process was terminated because of an Error:")
print(err.message)
sys.exit(1)
# let BaseError and all unexpected errors escalate, so that a stack trace is printed
except Exception as err:
logger.error(err)
raise InternalError from None

if not success:
logger.error("Terminate without success")
Expand Down

0 comments on commit 71a1737

Please sign in to comment.