Bug 1404067 - [tryselect] Improve error message on parameter mismatch, r?dustin draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Thu, 28 Sep 2017 15:25:34 -0400
changeset 672608 c7dc2f640e8fc532458630863bd06082239fdb76
parent 672593 cd9c8c48e4b3ded47a776f757008f3dcf570c59c
child 672688 61e6a62d308220cd5c2d23f35c8c72ba5d3c88e2
child 672691 9f731e41bb287b0f459bf3609dc3401f7257ce89
push id82296
push userahalberstadt@mozilla.com
push dateFri, 29 Sep 2017 12:55:25 +0000
reviewersdustin
bugs1404067
milestone58.0a1
Bug 1404067 - [tryselect] Improve error message on parameter mismatch, r?dustin MozReview-Commit-ID: GMiGuNApoUF
taskcluster/docs/mach.rst
taskcluster/taskgraph/parameters.py
tools/tryselect/tasks.py
--- a/taskcluster/docs/mach.rst
+++ b/taskcluster/docs/mach.rst
@@ -19,29 +19,36 @@ graph-generation process and output the 
    Get the target task graph
 
 ``mach taskgraph optimized``
    Get the optimized task graph
 
 ``mach taskgraph morphed``
    Get the morhped task graph
 
-Each of these commands takes an optional ``--parameters`` option giving a file
+See :doc:`how-tos` for further practical tips on debugging task-graph mechanics
+locally.
+
+Parameters
+----------
+
+Each of these commands takes an optional ``--parameters`` argument giving a file
 with parameters to guide the graph generation.  The decision task helpfully
 produces such a file on every run, and that is generally the easiest way to get
 a parameter file.  The parameter keys and values are described in
 :doc:`parameters`; using that information, you may modify an existing
 ``parameters.yml`` or create your own.  The ``--parameters`` option can also
-take an argument of the form ``project=<project>`` which will fetch the
-parameters from the latest push on that project; or ``task-id=<task-id>`` which
-will fetch the parameters from the given decision task. It defaults to
-``project=mozilla-central``.
+take the following forms:
 
-See :doc:`how-tos` for further practical tips on debugging task-graph mechanics
-locally.
+``project=<project>``
+   Fetch the parameters from the latest push on that project
+``task-id=<task-id>``
+   Fetch the parameters from the given decision task id
+
+If not specified, parameters will default to ``project=mozilla-central``.
 
 Taskgraph JSON Format
 ---------------------
 By default, the above commands will only output a list of tasks. Use `-J` flag
 to output full task definitions. For example:
 
 .. code-block:: shell
 
--- a/taskcluster/taskgraph/parameters.py
+++ b/taskcluster/taskgraph/parameters.py
@@ -5,16 +5,21 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import json
 import yaml
 from mozbuild.util import ReadOnlyDict
 
+
+class ParameterMismatch(Exception):
+    """Raised when a parameters.yml has extra or missing parameters."""
+
+
 # Please keep this list sorted and in sync with taskcluster/docs/parameters.rst
 PARAMETER_NAMES = set([
     'base_repository',
     'build_date',
     'filters',
     'head_ref',
     'head_repository',
     'head_rev',
@@ -45,17 +50,17 @@ class Parameters(ReadOnlyDict):
         if missing:
             msg.append("missing parameters: " + ", ".join(missing))
 
         extra = names - PARAMETER_NAMES
         if extra:
             msg.append("extra parameters: " + ", ".join(extra))
 
         if msg:
-            raise Exception("; ".join(msg))
+            raise ParameterMismatch("; ".join(msg))
 
     def __getitem__(self, k):
         if k not in PARAMETER_NAMES:
             raise KeyError("no such parameter {!r}".format(k))
         try:
             return super(Parameters, self).__getitem__(k)
         except KeyError:
             raise KeyError("taskgraph parameter {!r} not found".format(k))
--- a/tools/tryselect/tasks.py
+++ b/tools/tryselect/tasks.py
@@ -1,27 +1,43 @@
 # 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 os
+import sys
 
 from mozboot.util import get_state_dir
 from mozbuild.base import MozbuildObject
 from mozpack.files import FileFinder
 
 from taskgraph.generator import TaskGraphGenerator
-from taskgraph.parameters import load_parameters_file
+from taskgraph.parameters import (
+    ParameterMismatch,
+    load_parameters_file,
+)
 
 here = os.path.abspath(os.path.dirname(__file__))
 build = MozbuildObject.from_environment(cwd=here)
 
 
+PARAMETER_MISMATCH = """
+ERROR - The parameters being used to generate tasks differ from those defined
+in your working copy:
+
+    {}
+
+To fix this, either rebase onto the latest mozilla-central or pass in
+-p/--parameters. For more information on how to define parameters, see:
+https://firefox-source-docs.mozilla.org/taskcluster/taskcluster/mach.html#parameters
+"""
+
+
 def invalidate(cache):
     if not os.path.isfile(cache):
         return
 
     tc_dir = os.path.join(build.topsrcdir, 'taskcluster')
     tmod = max(os.path.getmtime(os.path.join(tc_dir, p)) for p, _ in FileFinder(tc_dir))
     cmod = os.path.getmtime(cache)
 
@@ -40,18 +56,22 @@ def generate_tasks(params=None, full=Fal
     if os.path.isfile(cache):
         with open(cache, 'r') as fh:
             return fh.read().splitlines()
 
     if not os.path.isdir(cache_dir):
         os.makedirs(cache_dir)
 
     print("Task configuration changed, generating {}".format(attr.replace('_', ' ')))
-    params = load_parameters_file(params)
-    params.check()
+    try:
+        params = load_parameters_file(params)
+        params.check()
+    except ParameterMismatch as e:
+        print(PARAMETER_MISMATCH.format(e.args[0]))
+        sys.exit(1)
 
     cwd = os.getcwd()
     os.chdir(build.topsrcdir)
 
     root = os.path.join(build.topsrcdir, 'taskcluster', 'ci')
     tg = getattr(TaskGraphGenerator(root_dir=root, parameters=params), attr)
     labels = [label for label in tg.graph.visit_postorder()]