Skip to content

Commit

Permalink
Update content_templates_parser.py (ansible-collections#657)
Browse files Browse the repository at this point in the history
* Update content_templates_parser.py

* Create update_error_msg.yaml

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update update_error_msg.yaml

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
rohitthakur2590 and pre-commit-ci[bot] authored Jul 5, 2024
1 parent a269f23 commit dc85f6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/update_error_msg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
trivial:
- Updated the error message for the content_templates parser to include the correct parser name and detailed error information.
7 changes: 3 additions & 4 deletions plugins/sub_plugins/cli_parser/content_templates_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

EXAMPLES = """
- name: "Run command and parse with native"
- name: "Run command and parse with content_templates"
ansible.utils.cli_parse:
command: "show bgp summary"
parser:
Expand All @@ -41,7 +41,7 @@


class CliParser(CliParserBase):
"""The native parser class
"""The content_templates parser class
Convert raw text to structured data using the resource module parser
"""

Expand Down Expand Up @@ -72,8 +72,7 @@ def parse(self, *_args, **kwargs):
try:
parser.PARSERS = template_obj
out = {"parsed": parser.parse()}
print(out)
return out
except Exception as exc:
msg = "Native parser returned an error while parsing. Error: {err}"
msg = "An error occurred during content_templates parsing. Error: {err}"
return {"errors": [msg.format(err=to_native(exc))]}

0 comments on commit dc85f6c

Please sign in to comment.