diff --git a/htsinfer/cli.py b/htsinfer/cli.py index 99cb9ad6..3fea80d4 100644 --- a/htsinfer/cli.py +++ b/htsinfer/cli.py @@ -4,6 +4,7 @@ import argparse import logging from pathlib import Path +from traceback import format_exc from typing import Dict import signal import sys @@ -331,6 +332,11 @@ def main() -> None: LOGGER.error('Execution interrupted.') sys.exit(128 + signal.SIGINT) + except Exception as exc: # pylint: disable=W0703 + LOGGER.error(f"{exc}") + LOGGER.debug(format_exc()) + sys.exit(2) + # conclude execution LOGGER.info("Done") sys.exit(hts_infer.state.value) diff --git a/tests/test_cli.py b/tests/test_cli.py index 58e0fbd2..8864a0fc 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -190,6 +190,17 @@ def test_keyboard_interrupt(self, monkeypatch): main() assert exc.value.code >= 128 + def test_generic_exception(self, monkeypatch): + """Test keyboard interrupt.""" + + monkeypatch.setattr( + 'htsinfer.cli.parse_args', + RaiseError(exc=Exception), + ) + with pytest.raises(SystemExit) as exc: + main() + assert exc.value.code == 2 + def test_main_as_script(): """Run as script."""