diff --git a/src/relic/core/cli.py b/src/relic/core/cli.py index daed3f0..b8ec1f3 100644 --- a/src/relic/core/cli.py +++ b/src/relic/core/cli.py @@ -28,7 +28,11 @@ List, ) -from relic.core.errors import UnboundCommandError, RelicArgParserError +from relic.core.errors import ( + UnboundCommandError, + RelicArgParserError, + RelicInputFileError, +) from relic.core.typeshed import entry_points @@ -410,8 +414,12 @@ def _run( if not hasattr(ns, "function"): raise UnboundCommandError(cmd) func = ns.function + result: Optional[int] = None with setup_cli_logging(ns, logger, log_setup_options) as cli_logger: - result: Optional[int] = func(ns, logger=cli_logger) + try: + result = func(ns, logger=cli_logger) + except RelicInputFileError as error: + cli_logger.info(f"relic: {error}") if result is None: # Assume success result = 0 return result diff --git a/src/relic/core/errors.py b/src/relic/core/errors.py index c5c3520..9fb11a1 100644 --- a/src/relic/core/errors.py +++ b/src/relic/core/errors.py @@ -52,6 +52,15 @@ class RelicToolError(Exception): """ +class RelicInputFileError(RelicToolError): + """ + An non critical error was raised during input file parsing. + + All non critical error raised during input file handling in this library and it's plugins should inherit + from this class. Only error message without trace is logged. + """ + + class CliError(RelicToolError): """ An error was raised by the command line interface. @@ -75,7 +84,7 @@ def __str__(self) -> str: return f"The '{self._name}' command was defined, but not bound to a function." -class MismatchError(Generic[_T], RelicToolError): +class MismatchError(Generic[_T], RelicInputFileError): """ An error where a received value did not match the expected value. """ @@ -100,7 +109,7 @@ class MagicMismatchError(MismatchError[bytes]): """ -class RelicSerializationError(RelicToolError): +class RelicSerializationError(RelicInputFileError): """ An error was raised while serializing an object. """ @@ -130,6 +139,7 @@ class RelicArgParserError(Exception): __all__ = [ "RelicToolError", + "RelicInputFileError", "MismatchError", "MagicMismatchError", "CliError",