Skip to content

Commit

Permalink
refactor: ♻️ Change to use __traceback__
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrew82 committed Mar 20, 2024
1 parent b5f18ea commit 6fcd4fa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nornir_nautobot/plugins/tasks/dispatcher/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,24 @@ 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.with_traceback)}``"
error_msg = f"`E1010:` There was a jinja2.exceptions.UndefinedError error: ``{str(exc.result.exception)}`` and ``{str(exc.result.exception.__traceback__)}``"
logger.error(error_msg, extra={"object": obj, "exc_info": True})
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.with_traceback)}``",
f"`E1011:` There was a jinja2.TemplateSyntaxError error: ``{str(exc.result.exception)}`` and ``{str(exc.result.exception.__traceback__)}``",
)
logger.error(error_msg, extra={"object": obj})
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.with_traceback)}``"
error_msg = f"`E1012:` There was an issue finding the template and a jinja2.TemplateNotFound error was raised: ``{str(exc.result.exception)}`` and ``{str(exc.result.exception.__traceback__)}``"
logger.error(error_msg, extra={"object": obj})
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.with_traceback)}``"
error_msg = f"`E1013:` There was an issue general Jinja error: ``{str(exc.result.exception)}`` and ``{str(exc.result.exception.__traceback__)}``"
logger.error(error_msg, extra={"object": obj})
raise NornirNautobotException(error_msg)

Expand Down

0 comments on commit 6fcd4fa

Please sign in to comment.