Skip to content

Commit

Permalink
now has display of last resort
Browse files Browse the repository at this point in the history
moved all display/color/err to use display.error
now also capture generic exceptions if they happen (never should!)
  • Loading branch information
bcoca committed Jul 5, 2015
1 parent 6a75125 commit f42b623
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions bin/ansible
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

########################################################
from __future__ import (absolute_import)
from __future__ import (absolute_import, print_function)
__metaclass__ = type

__requires__ = ['ansible']
Expand All @@ -38,10 +38,17 @@ import sys
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
from ansible.utils.display import Display

########################################################
########################################
### OUTPUT OF LAST RESORT ###
class LastResort(object):
def error(self, msg):
print(msg, file=sys.stderr)

########################################

if __name__ == '__main__':

display = LastResort()
cli = None
me = os.path.basename(sys.argv[0])

Expand Down Expand Up @@ -70,21 +77,24 @@ if __name__ == '__main__':

except AnsibleOptionsError as e:
cli.parser.print_help()
display.display(str(e), stderr=True, color='red')
display.error(str(e))
sys.exit(5)
except AnsibleParserError as e:
display.display(str(e), stderr=True, color='red')
display.error(str(e))
sys.exit(4)
# TQM takes care of these, but leaving comment to reserve the exit codes
# except AnsibleHostUnreachable as e:
# display.display(str(e), stderr=True, color='red')
# display.error(str(e))
# sys.exit(3)
# except AnsibleHostFailed as e:
# display.display(str(e), stderr=True, color='red')
# display.error(str(e))
# sys.exit(2)
except AnsibleError as e:
display.display(str(e), stderr=True, color='red')
display.error(str(e))
sys.exit(1)
except KeyboardInterrupt:
display.error("interrupted")
display.error("User interrupted execution")
sys.exit(99)
except Exception as e:
display.error("Unexpected Exception: %s" % str(e))
sys.exit(250)

0 comments on commit f42b623

Please sign in to comment.