Better error message when variable substitution fails. (Gary Oberbrunner)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 31 Dec 2004 14:21:11 +0000 (14:21 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Fri, 31 Dec 2004 14:21:11 +0000 (14:21 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1200 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Util.py
src/engine/SCons/UtilTests.py

index 7d5cc23cee9ddab128ff6f1995b3584cf8190d06..20842b43639db33737cc44e776eaf10157fe9605 100644 (file)
@@ -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
index c8905626aa899a344a15be9bbecad26ea567466a..d8f0a749c098691017afd2b7de44b12d52eb700b 100644 (file)
@@ -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:
index b6b04248be3a6109fda9a65a0bb37f415ea68a5d..3ae3b482f416f56e0aec366992af13013cc9ab1e 100644 (file)
@@ -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)