Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop hiding critical debug info in helpers (#988) #997

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sceptre/cli/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ def catch_exceptions(func):
simplified.
:returns: The decorated function.
"""
def logging_level():
logger = logging.getLogger(__name__)
return logger.getEffectiveLevel()

@wraps(func)
def decorated(*args, **kwargs):
"""
Invokes ``func``, catches expected errors, prints the error message and
exits sceptre with a non-zero exit code.
exits sceptre with a non-zero exit code. In debug mode, the original
exception is re-raised to assist debugging.
"""
try:
return func(*args, **kwargs)
except (SceptreException, BotoCoreError, ClientError, Boto3Error,
TemplateError) as error:
if logging_level() == logging.DEBUG:
raise
craighurley marked this conversation as resolved.
Show resolved Hide resolved
write(error)
sys.exit(1)

Expand Down
13 changes: 12 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,25 @@ def teardown_method(self, test_method):
self.patcher_StackActions.stop()

@patch("sys.exit")
def test_catch_excecptions(self, mock_exit):
def test_catch_exceptions(self, mock_exit):
@catch_exceptions
def raises_exception():
raise SceptreException()

raises_exception()
mock_exit.assert_called_once_with(1)

def test_catch_exceptions_debug_mode(self):
@catch_exceptions
def raises_exception():
raise SceptreException()

logger = logging.getLogger("sceptre")
logger.setLevel(logging.DEBUG)

with pytest.raises(SceptreException):
raises_exception()

@pytest.mark.parametrize("command,files,output", [
# one --var option
(
Expand Down