about summary refs log tree commit diff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-04T19·14+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-04T19·14+0200
commita5fe73094016973a50741db0c5d51ca96c14147b (patch)
tree28393198f2cd307db18ec160d7139b2e77077ddd /src/libexpr/eval.cc
parent27b44b8cf7072b09a1929ee44ba784b1c8d5211a (diff)
forceString: Show position info
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 5c88a34a92..30a8793ee7 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -140,7 +140,8 @@ static void * oomHandler(size_t requested)
 #endif
 
 
-static Symbol getName(const AttrName & name, EvalState & state, Env & env) {
+static Symbol getName(const AttrName & name, EvalState & state, Env & env)
+{
     if (name.symbol.set()) {
         return name.symbol;
     } else {
@@ -279,6 +280,11 @@ LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, con
     throw EvalError(format(s) % s2 % s3);
 }
 
+LocalNoInlineNoReturn(void throwEvalError(const char * s, const string & s2, const string & s3, const Pos & pos))
+{
+    throw EvalError(format(s) % s2 % s3 % pos);
+}
+
 LocalNoInlineNoReturn(void throwEvalError(const char * s, const Symbol & sym, const Pos & p1, const Pos & p2))
 {
     throw EvalError(format(s) % sym % p1 % p2);
@@ -1172,11 +1178,15 @@ void EvalState::forceFunction(Value & v, const Pos & pos)
 }
 
 
-string EvalState::forceString(Value & v)
+string EvalState::forceString(Value & v, const Pos & pos)
 {
     forceValue(v);
-    if (v.type != tString)
-        throwTypeError("value is %1% while a string was expected", v);
+    if (v.type != tString) {
+        if (pos)
+            throwTypeError("value is %1% while a string was expected, at %2%", v, pos);
+        else
+            throwTypeError("value is %1% while a string was expected", v);
+    }
     return string(v.string.s);
 }
 
@@ -1197,12 +1207,17 @@ string EvalState::forceString(Value & v, PathSet & context)
 }
 
 
-string EvalState::forceStringNoCtx(Value & v)
+string EvalState::forceStringNoCtx(Value & v, const Pos & pos)
 {
-    string s = forceString(v);
-    if (v.string.context)
-        throwEvalError("the string `%1%' is not allowed to refer to a store path (such as `%2%')",
-            v.string.s, v.string.context[0]);
+    string s = forceString(v, pos);
+    if (v.string.context) {
+        if (pos)
+            throwEvalError("the string `%1%' is not allowed to refer to a store path (such as `%2%'), at %3%",
+                v.string.s, v.string.context[0], pos);
+        else
+            throwEvalError("the string `%1%' is not allowed to refer to a store path (such as `%2%')",
+                v.string.s, v.string.context[0]);
+    }
     return s;
 }