Rev 5565: Give more context when unkwon refs are encountered. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Feb 17 00:04:25 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5565
revision-id: v.ladeuil+lp at free.fr-20110217000425-we9p43s21i01kd15
parent: v.ladeuil+lp at free.fr-20110216235803-rvxyf3w5viyz2fw8
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: interpolate
timestamp: Thu 2011-02-17 01:04:25 +0100
message:
  Give more context when unkwon refs are encountered.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-02-16 23:58:03 +0000
+++ b/bzrlib/config.py	2011-02-17 00:04:25 +0000
@@ -161,11 +161,11 @@
         :param env: An option dict defining additional configuration options or
             overriding existing ones.
 
-        :param _ref_stack: Private list containing the options being
-            interpolated to detect loops.
-
         :returns: The interpolated string.
         """
+        return self._interpolate_string(string, env)
+
+    def _interpolate_string(self, string, env=None, _ref_stack=None):
         if _ref_stack is None:
             # What references are currently resolved (to detect loops)
             _ref_stack = []
@@ -194,7 +194,10 @@
                     if name in _ref_stack:
                         raise errors.InterpolationLoop(string, _ref_stack)
                     _ref_stack.append(name)
-                    value = self._interpolate_option(name, env, _ref_stack)
+                    try:
+                        value = self._interpolate_option(name, env, _ref_stack)
+                    except KeyError:
+                        raise errors.InterpolationUnknownOption(name, string)
                     chunks.append(value)
                     _ref_stack.pop()
                     is_ref = False
@@ -210,11 +213,8 @@
             # 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
-            try:
-                value = self[name]
-            except KeyError:
-                raise errors.InterpolationUnknownOption(name)
-        return self.interpolate(value, env, ref_stack)
+            value = self[name]
+        return self._interpolate_string(value, env, ref_stack)
 
 
 class Config(object):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2011-02-16 23:58:03 +0000
+++ b/bzrlib/errors.py	2011-02-17 00:04:25 +0000
@@ -3233,7 +3233,8 @@
 
 class InterpolationUnknownOption(BzrError):
 
-    _fmt = 'Option %(name)s is not defined.'
+    _fmt = 'Option %(name)s is not defined while interpolating "%(string)s".'
 
-    def __init__(self, name):
+    def __init__(self, name, string):
         self.name = name
+        self.string = string



More information about the bazaar-commits mailing list