cli: standardize --debug/exception display
Each tool implements this slightly different (if at all). Pull it back
out and into the main runner so we get standard behvaior for all tools.
BUG=None
TEST=`cros flash ...` shows short error message
TEST=`cros --debug flash ...` shows full traceback
TEST=`./cbuildbot/run_tests` passes
CQ-DEPEND=CL:275395
Change-Id: Icbdc23a63dccbd8afee02bb48ef80f16323f5073
Reviewed-on: https://chromium-review.googlesource.com/274895
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros.py b/scripts/cros.py
index ff11c1f..0fd5e45 100644
--- a/scripts/cros.py
+++ b/scripts/cros.py
@@ -72,7 +72,21 @@
subcommand.upload_stats_timeout])
# TODO: to make command completion faster, send an interrupt signal to the
# stats uploader task after the subcommand completes.
- code = _RunSubCommand(subcommand)
+ try:
+ code = _RunSubCommand(subcommand)
+ except (commandline.ChrootRequiredError, commandline.ExecRequiredError):
+ # The higher levels want these passed back, so oblige.
+ raise
+ except Exception as e:
+ code = 1
+ logging.error('%s %s failed before completing.',
+ command.GetToolset(),
+ subcommand.command_name)
+ if namespace.debug:
+ raise
+ else:
+ logging.error(e)
+
if code is not None:
return code