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 7, 2021
1 parent 881c6bd commit fef7870
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 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
7 changes: 3 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ def teardown_method(self, test_method):
self.patcher_ConfigReader.stop()
self.patcher_StackActions.stop()

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

raises_exception()
mock_exit.assert_called_once_with(1)
with pytest.raises(SceptreException):
raises_exception()

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

0 comments on commit fef7870

Please sign in to comment.