Skip to content

Commit 98eaccc

Browse files
committed
change execute to run
Change-Id: I23a210c8771c206df14d2713a2e72ccd92402c43
1 parent a1bda21 commit 98eaccc

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

‎openstackclient/shell.py‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121
import os
2222
import sys
23+
import traceback
2324

2425
from cliff import app
2526
from cliff import command
@@ -75,6 +76,9 @@ def __init__(self):
7576
version=openstackclient.__version__,
7677
command_manager=commandmanager.CommandManager('openstack.cli'))
7778

79+
# Until we have command line arguments parsed, dump any stack traces
80+
self.dump_stack_trace = True
81+
7882
# This is instantiated in initialize_app() only when using
7983
# password flow auth
8084
self.auth_client = None
@@ -111,6 +115,18 @@ def __init__(self):
111115
help="show this help message and exit",
112116
)
113117

118+
def run(self, argv):
119+
try:
120+
super(OpenStackShell, self).run(argv)
121+
except Exception as e:
122+
if not logging.getLogger('').handlers:
123+
logging.basicConfig()
124+
if self.dump_stack_trace:
125+
self.log.error(traceback.format_exc(e))
126+
else:
127+
self.log.error('Exception raised: ' + str(e))
128+
return 1
129+
114130
def build_option_parser(self, description, version):
115131
parser = super(OpenStackShell, self).build_option_parser(
116132
description,
@@ -365,8 +381,10 @@ def initialize_app(self, argv):
365381
requests_log = logging.getLogger("requests")
366382
if self.options.debug:
367383
requests_log.setLevel(logging.DEBUG)
384+
self.dump_stack_trace = True
368385
else:
369386
requests_log.setLevel(logging.WARNING)
387+
self.dump_stack_trace = False
370388

371389
# Save default domain
372390
self.default_domain = self.options.os_default_domain
@@ -437,11 +455,7 @@ def interact(self):
437455

438456

439457
def main(argv=sys.argv[1:]):
440-
try:
441-
return OpenStackShell().run(argv)
442-
except Exception:
443-
return 1
444-
458+
return OpenStackShell().run(argv)
445459

446460
if __name__ == "__main__":
447461
sys.exit(main(sys.argv[1:]))

0 commit comments

Comments
 (0)