Skip to content

Commit

Permalink
fix: change exit code for unexpected errors
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueg committed Sep 5, 2023
1 parent 3dff395 commit d243b44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions htsinfer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit d243b44

Please sign in to comment.