diff --git a/sceptre/cli/helpers.py b/sceptre/cli/helpers.py index b8f9cbbc0..98c0b0071 100644 --- a/sceptre/cli/helpers.py +++ b/sceptre/cli/helpers.py @@ -1,5 +1,7 @@ import logging +import os import sys +import traceback from itertools import cycle from functools import partial, wraps @@ -32,14 +34,15 @@ def catch_exceptions(func): def decorated(*args, **kwargs): """ Invokes ``func``, catches expected errors, prints the error message and - re-raises. + exits sceptre with a non-zero exit code. """ try: return func(*args, **kwargs) except (SceptreException, BotoCoreError, ClientError, Boto3Error, - TemplateError) as error: - write(error) - raise + TemplateError): + if "DEBUG_ERRORS" in os.environ: + traceback.print_exc() + sys.exit(1) return decorated diff --git a/tests/test_cli.py b/tests/test_cli.py index 66f5120da..1fe02ac21 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -55,13 +55,14 @@ def teardown_method(self, test_method): self.patcher_ConfigReader.stop() self.patcher_StackActions.stop() - def test_catch_excecptions(self): + @patch("sys.exit") + def test_catch_excecptions(self, mock_exit): @catch_exceptions def raises_exception(): raise SceptreException() - with pytest.raises(SceptreException): - raises_exception() + raises_exception() + mock_exit.assert_called_once_with(1) @pytest.mark.parametrize("command,files,output", [ # one --var option