From: stevenknight Date: Fri, 31 Dec 2004 14:21:11 +0000 (+0000) Subject: Better error message when variable substitution fails. (Gary Oberbrunner) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0a032154048c8353fb5f8b50763741a659788400;p=scons.git Better error message when variable substitution fails. (Gary Oberbrunner) git-svn-id: http://scons.tigris.org/svn/scons/trunk@1200 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 7d5cc23c..20842b43 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -232,6 +232,9 @@ RELEASE 0.97 - XXX - Fix the private Conftest._Have() function so it doesn't change non-alphanumeric characters to underscores. + - Supply a better error message when a construction variable expansion + has an unknown attribute. + From Chris Pawling: - Have the linkloc tool use $MSVS_VERSION to select the Microsoft diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index c8905626..d8f0a749 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -612,6 +612,9 @@ def scons_subst(strSubst, env, mode=SUBST_RAW, target=None, source=None, gvars={ key = key[1:-1] try: s = eval(key, self.gvars, lvars) + except AttributeError, e: + raise SCons.Errors.UserError, \ + "Error substituting `%s': unknown attribute `%s'" % (key, e) except (IndexError, NameError, TypeError): return '' except SyntaxError,e: @@ -808,6 +811,9 @@ def scons_subst_list(strSubst, env, mode=SUBST_RAW, target=None, source=None, gv key = key[1:-1] try: s = eval(key, self.gvars, lvars) + except AttributeError, e: + raise SCons.Errors.UserError, \ + "Error substituting `%s': unknown attribute `%s'" % (key, e) except (IndexError, NameError, TypeError): return except SyntaxError,e: diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py index b6b04248..3ae3b482 100644 --- a/src/engine/SCons/UtilTests.py +++ b/src/engine/SCons/UtilTests.py @@ -450,6 +450,17 @@ class UtilTestCase(unittest.TestCase): gvars=gvars) assert newcom == "test foo baz s t", newcom + # Test that we handle attribute errors during expansion as expected. + try: + class Foo: + pass + scons_subst('${foo.bar}', env, gvars={'foo':Foo()}) + except SCons.Errors.UserError, e: + expect = "Error substituting `foo.bar': unknown attribute `bar'" + assert str(e) == expect, e + else: + raise AssertionError, "did not catch expected UserError" + # Test that we handle syntax errors during expansion as expected. try: scons_subst('$foo.bar.3.0', env) @@ -853,6 +864,17 @@ class UtilTestCase(unittest.TestCase): del subst_list_cases[:4] assert failed == 0, "%d subst() mode cases failed" % failed + # Test that we handle attribute errors during expansion as expected. + try: + class Foo: + pass + scons_subst_list('${foo.bar}', env, gvars={'foo':Foo()}) + except SCons.Errors.UserError, e: + expect = "Error substituting `foo.bar': unknown attribute `bar'" + assert str(e) == expect, e + else: + raise AssertionError, "did not catch expected UserError" + # Test that we handle syntax errors during expansion as expected. try: scons_subst_list('$foo.bar.3.0', env)