Rev 5564: Detect unknown references during interpolation. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Feb 16 23:58:03 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5564
revision-id: v.ladeuil+lp at free.fr-20110216235803-rvxyf3w5viyz2fw8
parent: v.ladeuil+lp at free.fr-20110204171458-dwmwixlsbg1cjoad
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: interpolate
timestamp: Thu 2011-02-17 00:58:03 +0100
message:
Detect unknown references during interpolation.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-02-04 16:56:58 +0000
+++ b/bzrlib/config.py 2011-02-16 23:58:03 +0000
@@ -210,7 +210,10 @@
# FIXME: This is a limited implementation, what we really need
# is a way to query the bzr config for the value of an option,
# respecting the scope rules -- vila 20101222
- value = self[name]
+ try:
+ value = self[name]
+ except KeyError:
+ raise errors.InterpolationUnknownOption(name)
return self.interpolate(value, env, ref_stack)
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2011-02-04 15:48:32 +0000
+++ b/bzrlib/errors.py 2011-02-16 23:58:03 +0000
@@ -3230,3 +3230,10 @@
def __init__(self, string, refs):
self.string = string
self.refs = '->'.join(refs)
+
+class InterpolationUnknownOption(BzrError):
+
+ _fmt = 'Option %(name)s is not defined.'
+
+ def __init__(self, name):
+ self.name = name
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-02-04 17:14:58 +0000
+++ b/bzrlib/tests/test_config.py 2011-02-16 23:58:03 +0000
@@ -367,6 +367,11 @@
c = self.get_config('foo=xxx')
self.assertInterpolate('xxx', c, '{foo}')
+ def test_unknown_ref(self):
+ c = self.get_config('')
+ self.assertRaises(errors.InterpolationUnknownOption,
+ c.interpolate, '{foo}')
+
def test_indirect_ref(self):
c = self.get_config('''
foo=xxx
More information about the bazaar-commits
mailing list