changeset 39:8715e5cc59ac

Print a warning if a variable cannot be expanded. This is to simplify debugging.
author Franz Glasner <hg@dom66.de>
date Thu, 07 Apr 2016 23:12:12 +0200
parents ce2443285000
children 8d66aef2f7fb
files configmix/config.py
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/configmix/config.py	Thu Mar 31 19:19:34 2016 +0200
+++ b/configmix/config.py	Thu Apr 07 23:12:12 2016 +0200
@@ -6,6 +6,7 @@
 
 from __future__ import division, absolute_import, print_function
 
+import warnings
 try:
     from collections import OrderedDict as ConfigurationBase
 except ImportError:
@@ -193,7 +194,14 @@
             if end < 0:
                 return s
             varname, filters = self._split_filters(s[start+2:end])
-            varvalue = self._apply_filters(filters, self.getvar_s(varname))
+            try:
+                varvalue = self._apply_filters(filters, self.getvar_s(varname))
+            except KeyError:
+                warnings.warn("Cannot expand variable %r in string "
+                              "%r" % (varname, s, ),
+                              UserWarning,
+                              stacklevel=1)
+                raise
             if varvalue is None:
                 varvalue = u("")
             replaced = u(b"{0}{1}").format(s[:start], varvalue)