Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to implement Craig Hurley's suggestion
Browse files Browse the repository at this point in the history
alex-harvey-z3q committed Oct 15, 2021
1 parent eaf0a1b commit d0b8e7d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions sceptre/cli/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import logging
import sys
import traceback

from itertools import cycle
from functools import partial, wraps

@@ -29,18 +27,24 @@ 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
re-raises.
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 "DEBUG_ERRORS" in os.environ:
traceback.print_exc()
if logging_level() == logging.DEBUG:
raise
write(error)
sys.exit(1)

return decorated

0 comments on commit d0b8e7d

Please sign in to comment.