Bug 1258497: wrap mach Commands in try/except; r=gps
authorDustin J. Mitchell <dustin@mozilla.com>
Mon, 16 May 2016 17:44:24 +0000
changeset 336651 7fe18230f273f0e0780048056dc50dec026a18c5
parent 336650 c17e66a20cb3e167420df885f94c6c010d1f6089
child 336652 9ffc0498ad7efb3a748b8a46be8cfa56002ec40b
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1258497
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1258497: wrap mach Commands in try/except; r=gps MozReview-Commit-ID: FTPDTjw4gR
taskcluster/mach_commands.py
taskcluster/taskgraph/parameters.py
--- a/taskcluster/mach_commands.py
+++ b/taskcluster/mach_commands.py
@@ -2,17 +2,17 @@
 
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import sys
-import textwrap
+import traceback
 
 from mach.decorators import (
     CommandArgument,
     CommandProvider,
     Command,
     SubCommand,
 )
 
@@ -131,30 +131,37 @@ class MachCommands(MachCommandBase):
     def taskgraph_decision(self, **options):
         """Run the decision task: generate a task graph and submit to
         TaskCluster.  This is only meant to be called within decision tasks,
         and requires a great many arguments.  Commands like `mach taskgraph
         optimized` are better suited to use on the command line, and can take
         the parameters file generated by a decision task.  """
 
         import taskgraph.decision
-        return taskgraph.decision.taskgraph_decision(self.log, options)
+        try:
+            return taskgraph.decision.taskgraph_decision(self.log, options)
+        except Exception as e:
+            traceback.print_exc()
+            sys.exit(1)
 
     def show_taskgraph(self, graph_attr, options):
         import taskgraph.parameters
         import taskgraph.target_tasks
         import taskgraph.generator
 
-        parameters = taskgraph.parameters.load_parameters_file(options)
+        try:
+            parameters = taskgraph.parameters.load_parameters_file(options)
 
-        target_tasks_method = parameters.get('target_tasks_method', 'all_tasks')
-        target_tasks_method = taskgraph.target_tasks.get_method(target_tasks_method)
-        tgg = taskgraph.generator.TaskGraphGenerator(
-            root_dir=options['root'],
-            log=self.log,
-            parameters=parameters,
-            target_tasks_method=target_tasks_method)
+            target_tasks_method = parameters.get('target_tasks_method', 'all_tasks')
+            target_tasks_method = taskgraph.target_tasks.get_method(target_tasks_method)
+            tgg = taskgraph.generator.TaskGraphGenerator(
+                root_dir=options['root'],
+                log=self.log,
+                parameters=parameters,
+                target_tasks_method=target_tasks_method)
 
-        tg = getattr(tgg, graph_attr)
+            tg = getattr(tgg, graph_attr)
 
-        for label in tg.graph.visit_postorder():
-            print(tg.tasks[label])
-
+            for label in tg.graph.visit_postorder():
+                print(tg.tasks[label])
+        except Exception as e:
+            traceback.print_exc()
+            sys.exit(1)
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -28,18 +28,17 @@ def load_parameters_file(options):
     if not filename:
         return Parameters()
     with open(filename) as f:
         if filename.endswith('.yml'):
             return Parameters(**yaml.safe_load(f))
         elif filename.endswith('.json'):
             return Parameters(**json.load(f))
         else:
-            print("Parameters file `{}` is not JSON or YAML".format(filename))
-            sys.exit(1)
+            raise TypeError("Parameters file `{}` is not JSON or YAML".format(filename))
 
 def get_decision_parameters(options):
     """
     Load parameters from the command-line options for 'taskgraph decision'.
     """
     return Parameters({n: options[n] for n in [
         'base_repository',
         'head_repository',