Make stats upload more robust.
Print exceptions resulting from creation of the Stats object, but don't
quit the script.
BUG=chromium:236714
TEST=Unit tests, ran locally.
Change-Id: Ica6ec7fd9bcc5b7b54de69af391e4e2e8258e37b
Reviewed-on: https://gerrit.chromium.org/gerrit/49611
Commit-Queue: Ryan Cui <rcui@chromium.org>
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Ryan Cui <rcui@chromium.org>
diff --git a/scripts/cros.py b/scripts/cros.py
index 07d9fdf..e152f6c 100644
--- a/scripts/cros.py
+++ b/scripts/cros.py
@@ -44,9 +44,10 @@
with stats.UploadContext() as queue:
if subcommand.upload_stats:
cmd_base = subcommand.options.cros_class.command_name
- cmd_stats = stats.Stats(cmd_line=sys.argv, cmd_base=cmd_base)
- queue.put([cmd_stats, stats.StatsUploader.URL,
- subcommand.upload_stats_timeout])
+ cmd_stats = stats.Stats.SafeInit(cmd_line=sys.argv, cmd_base=cmd_base)
+ if cmd_stats:
+ queue.put([cmd_stats, stats.StatsUploader.URL,
+ subcommand.upload_stats_timeout])
# TODO: to make command completion faster, send an interrupt signal to the
# stats uploader task after the subcommand completes.
_RunSubCommand(subcommand)