From 5e5cccde062fe18290048ab4adb4b2270fdf6c94 Mon Sep 17 00:00:00 2001 From: Fredrik Medley Date: Thu, 29 Mar 2018 15:40:06 +0200 Subject: Fix EnvironmentError printing bug EnvironmentErrors does not need to have the attributes strerror or errno. This commit makes the code robust for such situation. One example of such EnvironmentError is CacheDir.py: raise SCons.Errors.EnvironmentError(msg) Signed-off-by: Fredrik Medley --- src/CHANGES.txt | 5 +++++ src/engine/SCons/Errors.py | 11 +++++------ src/engine/SCons/ErrorsTests.py | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 64c0893..4d6d191 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -48,6 +48,11 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE Specifically, this fixes the test cases use by Configure.CheckCC() which would fail when using -Wstrict-prototypes. + From Fredrik Medley: + - Fix exception when printing of EnviromentError messages. + Specifically, this fixes error reporting of the race condition when + initializing the cache which error previously was hidden. + RELEASE 3.0.1 - Mon, 12 Nov 2017 15:31:33 -0700 diff --git a/src/engine/SCons/Errors.py b/src/engine/SCons/Errors.py index dae20b2..3746d5d 100644 --- a/src/engine/SCons/Errors.py +++ b/src/engine/SCons/Errors.py @@ -190,14 +190,13 @@ def convert_to_BuildError(status, exc_info=None): # error, which might be different from the target being built # (for example, failure to create the directory in which the # target file will appear). - try: - filename = status.filename - except AttributeError: - filename = None + filename = getattr(status, 'filename', None) + strerror = getattr(status, 'strerror', str(status)) + errno = getattr(status, 'errno', 2) buildError = BuildError( - errstr=status.strerror, - status=status.errno, + errstr=strerror, + status=errno, exitstatus=2, filename=filename, exc_info=exc_info) diff --git a/src/engine/SCons/ErrorsTests.py b/src/engine/SCons/ErrorsTests.py index c38158d..7819580 100644 --- a/src/engine/SCons/ErrorsTests.py +++ b/src/engine/SCons/ErrorsTests.py @@ -23,6 +23,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import errno +import os import sys import unittest @@ -100,6 +102,29 @@ class ErrorsTestCase(unittest.TestCase): except SCons.Errors.ExplicitExit as e: assert e.node == "node" + def test_convert_EnvironmentError_to_BuildError(self): + """Test the convert_to_BuildError function on EnvironmentError + exceptions. + """ + ee = SCons.Errors.EnvironmentError("test env error") + be = SCons.Errors.convert_to_BuildError(ee) + assert be.errstr == "test env error" + assert be.status == 2 + assert be.exitstatus == 2 + assert be.filename is None + + def test_convert_OSError_to_BuildError(self): + """Test the convert_to_BuildError function on OSError + exceptions. + """ + ose = OSError(7, 'test oserror') + be = SCons.Errors.convert_to_BuildError(ose) + assert be.errstr == 'test oserror' + assert be.status == 7 + assert be.exitstatus == 2 + assert be.filename is None + + if __name__ == "__main__": suite = unittest.makeSuite(ErrorsTestCase, 'test_') TestUnit.run(suite) -- cgit v0.12