Skip to content

Commit

Permalink
raises custom exception on parsing error
Browse files Browse the repository at this point in the history
Caution: This is technically a breaking change.

Closes networktocode#369
  • Loading branch information
Kircheneer committed Apr 5, 2024
1 parent 49bf2ba commit 05f40f4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ntc_templates/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
HAS_CLITABLE = False


class ParsingException(Exception):
"""Error that is raised when TextFSM hits an `Error` state."""


def _get_template_dir():
template_dir = os.environ.get("NTC_TEMPLATES_DIR")
if template_dir is None:
Expand Down Expand Up @@ -57,9 +61,7 @@ def parse_output(platform=None, command=None, data=None):
cli_table.ParseCmd(data, attrs)
structured_data = _clitable_to_dict(cli_table)
except clitable.CliTableError as err:
raise Exception( # pylint: disable=broad-exception-raised
f'Unable to parse command "{command}" on platform {platform} - {str(err)}'
) from err
raise ParsingException(f'Unable to parse command "{command}" on platform {platform} - {str(err)}') from err
# Invalid or Missing template
# module.fail_json(msg='parsing error', error=str(e))
# rather than fail, fallback to return raw text
Expand Down

0 comments on commit 05f40f4

Please sign in to comment.