Skip to content

Commit

Permalink
refactor: ♻️ Change to logging with_traceback instead of re-raise
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew82 committed Mar 20, 2024
1 parent 2013e66 commit f50173d
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,30 +173,26 @@ def generate_config(
)[0].result
except NornirSubTaskError as exc:
if isinstance(exc.result.exception, jinja2.exceptions.UndefinedError): # pylint: disable=no-else-raise
error_msg = f"`E1010:` There was a jinja2.exceptions.UndefinedError error: ``{str(exc.result.exception)}``"
error_msg = f"`E1010:` There was a jinja2.exceptions.UndefinedError error: ``{exc.result.exception.with_traceback}``"
logger.error(error_msg, extra={"object": obj, "exc_info": True})
# raise NornirNautobotException(error_msg)
raise exc.result.exception
raise NornirNautobotException(error_msg)

elif isinstance(exc.result.exception, jinja2.TemplateSyntaxError):
error_msg = (
f"`E1011:` There was a jinja2.TemplateSyntaxError error: ``{str(exc.result.exception)}``",
f"`E1011:` There was a jinja2.TemplateSyntaxError error: ``{exc.result.exception.with_traceback}``",
)
logger.error(error_msg, extra={"object": obj})
# raise NornirNautobotException(error_msg)
raise exc.result.exception
raise NornirNautobotException(error_msg)

elif isinstance(exc.result.exception, jinja2.TemplateNotFound):
error_msg = f"`E1012:` There was an issue finding the template and a jinja2.TemplateNotFound error was raised: ``{str(exc.result.exception)}``"
error_msg = f"`E1012:` There was an issue finding the template and a jinja2.TemplateNotFound error was raised: ``{exc.result.exception.with_traceback}``"
logger.error(error_msg, extra={"object": obj})
# raise NornirNautobotException(error_msg)
raise exc.result.exception
raise NornirNautobotException(error_msg)

elif isinstance(exc.result.exception, jinja2.TemplateError):
error_msg = f"`E1013:` There was an issue general Jinja error: ``{str(exc.result.exception)}``"
error_msg = f"`E1013:` There was an issue general Jinja error: ``{exc.result.exception.with_traceback}``"
logger.error(error_msg, extra={"object": obj})
# raise NornirNautobotException(error_msg)
raise exc.result.exception
raise NornirNautobotException(error_msg)

error_msg = (
f"`E1014:` Failed with an unknown issue. `{exc.result.exception}`"
Expand Down

0 comments on commit f50173d

Please sign in to comment.