Bug 1258497: wrap mach Commands in try/except; r=gps
MozReview-Commit-ID: FTPDTjw4gR
--- 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',