Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/relic/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/relic/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
"""
Expand All @@ -100,7 +109,7 @@ class MagicMismatchError(MismatchError[bytes]):
"""


class RelicSerializationError(RelicToolError):
class RelicSerializationError(RelicInputFileError):
"""
An error was raised while serializing an object.
"""
Expand Down Expand Up @@ -130,6 +139,7 @@ class RelicArgParserError(Exception):

__all__ = [
"RelicToolError",
"RelicInputFileError",
"MismatchError",
"MagicMismatchError",
"CliError",
Expand Down