1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Don't wrap text for AnsibleParserError

This allows not messing up the wonderful error reporting that is
carefully created. Instead of:

    $ ansible-playbook foo.yml
     [ERROR]: ERROR! 'foo' is not a valid attribute for a Task  The error appears
    to have been in '/Users/marca/dev/git-repos/ansible/foo.yml': line 4, column 7,
    but may be elsewhere in the file depending on the exact syntax problem.  The
    offending line appears to be:    tasks:     - name: do something       ^ here

we get:

    $ ansible-playbook foo.yml
    ERROR! 'foo' is not a valid attribute for a Task

    The error appears to have been in '/Users/marca/dev/git-repos/ansible/foo.yml': line 4, column 7, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

      tasks:
        - name: do something
          ^ here

which is much nicer.
This commit is contained in:
Marc Abramowitz 2015-07-07 09:31:00 -07:00
parent d198b18c14
commit 314bae2a9e
2 changed files with 8 additions and 5 deletions

View file

@ -80,7 +80,7 @@ if __name__ == '__main__':
display.error(str(e)) display.error(str(e))
sys.exit(5) sys.exit(5)
except AnsibleParserError as e: except AnsibleParserError as e:
display.error(str(e)) display.error(str(e), wrap_text=False)
sys.exit(4) sys.exit(4)
# TQM takes care of these, but leaving comment to reserve the exit codes # TQM takes care of these, but leaving comment to reserve the exit codes
# except AnsibleHostUnreachable as e: # except AnsibleHostUnreachable as e:

View file

@ -182,10 +182,13 @@ class Display:
(out, err) = cmd.communicate() (out, err) = cmd.communicate()
self.display("%s\n" % out, color=color) self.display("%s\n" % out, color=color)
def error(self, msg): def error(self, msg, wrap_text=True):
new_msg = "\n[ERROR]: %s" % msg if wrap_text:
wrapped = textwrap.wrap(new_msg, 79) new_msg = "\n[ERROR]: %s" % msg
new_msg = "\n".join(wrapped) + "\n" wrapped = textwrap.wrap(new_msg, 79)
new_msg = "\n".join(wrapped) + "\n"
else:
new_msg = msg
if new_msg not in self._errors: if new_msg not in self._errors:
self.display(new_msg, color='red', stderr=True) self.display(new_msg, color='red', stderr=True)
self._errors[new_msg] = 1 self._errors[new_msg] = 1