From 4df0a08a5e29135f6a4f45c872a03fa67bbff8cb Mon Sep 17 00:00:00 2001 From: Alex Harvey Date: Wed, 7 Apr 2021 04:38:10 +1000 Subject: [PATCH] [Resolve #988] Stop hiding debug info in helpers Before this, the catch_exceptions function in cli/helpers would catch a range of exceptions and then hide all but the error message from the caller. Over the years, this has caused myself and others quite a lot of lost time, as it is now often quite unclear what caused Sceptre to fail. Simply re-raising the original exception provides valuable information to allow users of Sceptre to debug their failing code. --- sceptre/cli/helpers.py | 5 ++--- tests/test_cli.py | 12 +----------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/sceptre/cli/helpers.py b/sceptre/cli/helpers.py index 69edba63f..ffce230f3 100644 --- a/sceptre/cli/helpers.py +++ b/sceptre/cli/helpers.py @@ -1,5 +1,4 @@ import logging -import sys from functools import partial, wraps import json @@ -30,14 +29,14 @@ def catch_exceptions(func): def decorated(*args, **kwargs): """ Invokes ``func``, catches expected errors, prints the error message and - exits sceptre with a non-zero exit code. + re-raises. """ try: return func(*args, **kwargs) except (SceptreException, BotoCoreError, ClientError, Boto3Error, TemplateError) as error: write(error) - sys.exit(1) + raise return decorated diff --git a/tests/test_cli.py b/tests/test_cli.py index d13d43716..3ea77bbd4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,9 +16,8 @@ from sceptre.plan.actions import StackActions from sceptre.stack_status import StackStatus from sceptre.cli.helpers import setup_logging, write, ColouredFormatter -from sceptre.cli.helpers import CustomJsonEncoder, catch_exceptions +from sceptre.cli.helpers import CustomJsonEncoder from botocore.exceptions import ClientError -from sceptre.exceptions import SceptreException class TestCli(object): @@ -55,15 +54,6 @@ def teardown_method(self, test_method): self.patcher_ConfigReader.stop() self.patcher_StackActions.stop() - @patch("sys.exit") - def test_catch_excecptions(self, mock_exit): - @catch_exceptions - def raises_exception(): - raise SceptreException() - - raises_exception() - mock_exit.assert_called_once_with(1) - @pytest.mark.parametrize("command,files,output", [ # one --var option (