Skip to content

Commit

Permalink
[Resolve #988] Stop hiding debug info in helpers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alex-harvey-z3q committed Apr 6, 2021
1 parent 881c6bd commit 4df0a08
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
5 changes: 2 additions & 3 deletions sceptre/cli/helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import sys
from functools import partial, wraps

import json
Expand Down Expand Up @@ -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

Expand Down
12 changes: 1 addition & 11 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
(
Expand Down

0 comments on commit 4df0a08

Please sign in to comment.