summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Knight <knight@baldmt.com>2004-12-31 14:21:11 (GMT)
committerSteven Knight <knight@baldmt.com>2004-12-31 14:21:11 (GMT)
commitaa46ffde2fadeb6dbbc956a17c74013e8695e53c (patch)
tree804b47e0668e9234aabcb2018853cc595562f60f
parent73420316898a05bbb36d525d9fdbd5dc0412eec3 (diff)
downloadSCons-aa46ffde2fadeb6dbbc956a17c74013e8695e53c.zip
SCons-aa46ffde2fadeb6dbbc956a17c74013e8695e53c.tar.gz
SCons-aa46ffde2fadeb6dbbc956a17c74013e8695e53c.tar.bz2
Better error message when variable substitution fails. (Gary Oberbrunner)
-rw-r--r--src/CHANGES.txt3
-rw-r--r--src/engine/SCons/Util.py6
-rw-r--r--src/engine/SCons/UtilTests.py22
3 files changed, 31 insertions, 0 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 7d5cc23..20842b4 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 c890562..d8f0a74 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 b6b0424..3ae3b48 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)