Bug 1473498 - [mozbuild.mozconfig] Improve error message in MozconfigLoadException r=glandium
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Tue, 27 Aug 2019 03:03:49 +0000
changeset 553782 b51268c0040b67b03a3f02a45c437476fc1a810e
parent 553781 9b36ad9d6c8ad3153f70e7601897a4e2258eb7d1
child 553783 983a86c020c9ac14397855a5415a751bb23d897c
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1473498
milestone70.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 1473498 - [mozbuild.mozconfig] Improve error message in MozconfigLoadException r=glandium Without the output, this exception wasn't being very helpful. Differential Revision: https://phabricator.services.mozilla.com/D42015
python/mozbuild/mozbuild/base.py
python/mozbuild/mozbuild/mozconfig.py
python/mozbuild/mozbuild/test/test_mozconfig.py
--- a/python/mozbuild/mozbuild/base.py
+++ b/python/mozbuild/mozbuild/base.py
@@ -875,26 +875,17 @@ class MachCommandBase(MozbuildObject):
                   'typically caused by having a mozconfig pointing to a '
                   'different object directory from the current working '
                   'directory. To solve this problem, ensure you do not have a '
                   'default mozconfig in searched paths.' % (e.objdir1,
                                                             e.objdir2))
             sys.exit(1)
 
         except MozconfigLoadException as e:
-            print('Error loading mozconfig: ' + e.path)
-            print('')
             print(e.message)
-            if e.output:
-                print('')
-                print('mozconfig output:')
-                print('')
-                for line in e.output:
-                    print(line)
-
             sys.exit(1)
 
         MozbuildObject.__init__(self, topsrcdir, context.settings,
                                 context.log_manager, topobjdir=topobjdir)
 
         self._mach_context = context
 
         # Incur mozconfig processing so we have unified error handling for
@@ -903,26 +894,17 @@ class MachCommandBase(MozbuildObject):
         try:
             self.mozconfig
 
         except MozconfigFindException as e:
             print(e.message)
             sys.exit(1)
 
         except MozconfigLoadException as e:
-            print('Error loading mozconfig: ' + e.path)
-            print('')
             print(e.message)
-            if e.output:
-                print('')
-                print('mozconfig output:')
-                print('')
-                for line in e.output:
-                    print(line)
-
             sys.exit(1)
 
         # Always keep a log of the last command, but don't do that for mach
         # invokations from scripts (especially not the ones done by the build
         # system itself).
         if (os.isatty(sys.stdout.fileno()) and
                 not getattr(self, 'NO_AUTO_LOG', False)):
             self._ensure_state_subdir_exists('.')
--- a/python/mozbuild/mozbuild/mozconfig.py
+++ b/python/mozbuild/mozbuild/mozconfig.py
@@ -5,16 +5,17 @@
 from __future__ import absolute_import, print_function, unicode_literals
 
 import filecmp
 import os
 import re
 import sys
 import subprocess
 import traceback
+from textwrap import dedent
 
 from mozpack import path as mozpath
 from mozbuild.util import system_encoding
 
 
 MOZ_MYCONFIG_ERROR = '''
 The MOZ_MYCONFIG environment variable to define the location of mozconfigs
 is deprecated. If you wish to define the mozconfig path via an environment
@@ -49,16 +50,30 @@ class MozconfigLoadException(Exception):
     """Raised when a mozconfig could not be loaded properly.
 
     This typically indicates a malformed or misbehaving mozconfig file.
     """
 
     def __init__(self, path, message, output=None):
         self.path = path
         self.output = output
+
+        message = dedent("""
+        Error loading mozconfig: {path}
+
+        {message}
+        """).format(path=self.path, message=message).lstrip()
+
+        if self.output:
+            message += dedent("""
+            mozconfig output:
+
+            {output}
+            """).format(output="\n".join(self.output))
+
         Exception.__init__(self, message)
 
 
 class MozconfigLoader(object):
     """Handles loading and parsing of mozconfig files."""
 
     RE_MAKE_VARIABLE = re.compile('''
         ^\s*                    # Leading whitespace
--- a/python/mozbuild/mozbuild/test/test_mozconfig.py
+++ b/python/mozbuild/mozbuild/test/test_mozconfig.py
@@ -450,17 +450,17 @@ class TestMozconfigLoader(unittest.TestC
         with NamedTemporaryFile(mode='w') as mozconfig:
             mozconfig.write('echo "hello world"\n')
             mozconfig.write('exit 1\n')
             mozconfig.flush()
 
             with self.assertRaises(MozconfigLoadException) as e:
                 self.get_loader().read_mozconfig(mozconfig.name)
 
-            self.assertTrue(e.exception.message.startswith(
-                'Evaluation of your mozconfig exited with an error'))
+            self.assertIn('Evaluation of your mozconfig exited with an error',
+                          e.exception.message)
             self.assertEquals(e.exception.path,
                               mozconfig.name.replace(os.sep, '/'))
             self.assertEquals(e.exception.output, ['hello world'])
 
 
 if __name__ == '__main__':
     main()