Exit both command-line tools with failure status on operational errors
This commit is contained in:
parent
dc24c4d4fe
commit
bc37483b1a
3 changed files with 20 additions and 0 deletions
|
|
@ -212,6 +212,7 @@ def main() -> None:
|
||||||
exit()
|
exit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
|
raise SystemExit(1) from e
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,7 @@ def main() -> None:
|
||||||
exit()
|
exit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
raise SystemExit(1) from e
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
|
import importlib
|
||||||
from threading import Event
|
from threading import Event
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
from watchdog.events import FileClosedEvent, FileModifiedEvent, FileMovedEvent
|
from watchdog.events import FileClosedEvent, FileModifiedEvent, FileMovedEvent
|
||||||
|
|
||||||
from great_ai.deploy.reload_event_handler import ReloadEventHandler
|
from great_ai.deploy.reload_event_handler import ReloadEventHandler
|
||||||
|
|
@ -25,3 +28,18 @@ def test_reload_debounces_edit_and_replacement_events() -> None:
|
||||||
handler.close()
|
handler.close()
|
||||||
handler.dispatch(FileModifiedEvent("service.py"))
|
handler.dispatch(FileModifiedEvent("service.py"))
|
||||||
assert calls == ["restart"]
|
assert calls == ["restart"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
"module_name, operation",
|
||||||
|
[
|
||||||
|
("great_ai.__main__", "serve"),
|
||||||
|
("great_ai.large_file.__main__", "handle_command"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_cli_operational_errors_exit_nonzero(module_name: str, operation: str) -> None:
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
with patch.object(module, operation, side_effect=ValueError("failed")):
|
||||||
|
with pytest.raises(SystemExit) as error:
|
||||||
|
module.main()
|
||||||
|
assert error.value.code == 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue