mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Allow full exception tracebacks to be displayed with increased verbosity
This commit is contained in:
parent
614c626ed0
commit
6d50a261c5
1 changed files with 9 additions and 1 deletions
10
bin/ansible
10
bin/ansible
|
@ -34,6 +34,7 @@ except Exception:
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
from ansible.errors import AnsibleError, AnsibleOptionsError, AnsibleParserError
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
|
@ -41,9 +42,11 @@ from ansible.utils.display import Display
|
||||||
########################################
|
########################################
|
||||||
### OUTPUT OF LAST RESORT ###
|
### OUTPUT OF LAST RESORT ###
|
||||||
class LastResort(object):
|
class LastResort(object):
|
||||||
def error(self, msg):
|
def display(self, msg):
|
||||||
print(msg, file=sys.stderr)
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
|
error = display
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -96,5 +99,10 @@ if __name__ == '__main__':
|
||||||
display.error("User interrupted execution")
|
display.error("User interrupted execution")
|
||||||
sys.exit(99)
|
sys.exit(99)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
have_cli_options = cli is not None and cli.options is not None
|
||||||
display.error("Unexpected Exception: %s" % str(e))
|
display.error("Unexpected Exception: %s" % str(e))
|
||||||
|
if not have_cli_options or have_cli_options and cli.options.verbosity > 2:
|
||||||
|
display.display("the full traceback was:\n\n%s" % traceback.format_exc())
|
||||||
|
else:
|
||||||
|
display.display("to see the full traceback, use -vvv")
|
||||||
sys.exit(250)
|
sys.exit(250)
|
||||||
|
|
Loading…
Reference in a new issue