aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-03-06 14:24:08 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-03-06 14:24:08 +0100
commit5badc8f9758a0547b492ea0077e50c9ffd4f8424 (patch)
treede07cae8bbb7c10a34e5546d45ef1cb964a455c3 /src/libexpr/eval.cc
parent9f3eb56b460ad14647b90f9fc841776daf9beb47 (diff)
Improve error message
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index d82d1d6aa..4404e04eb 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -765,6 +765,23 @@ void ExprVar::eval(EvalState & state, Env & env, Value & v)
}
+static string showAttrPath(EvalState & state, Env & env, const AttrPath & attrPath)
+{
+ std::ostringstream out;
+ bool first = true;
+ for (auto & i : attrPath) {
+ if (!first) out << '.'; else first = false;
+ try {
+ out << getName(i, state, env);
+ } catch (Error & e) {
+ assert(!i.symbol.set());
+ out << "\"${" << *i.expr << "}\"";
+ }
+ }
+ return out.str();
+}
+
+
unsigned long nrLookups = 0;
void ExprSelect::eval(EvalState & state, Env & env, Value & v)
@@ -791,16 +808,8 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
}
} else {
state.forceAttrs(*vAttrs, pos);
- if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) {
- AttrPath staticPath;
- AttrPath::const_iterator j;
- for (j = attrPath.begin(); j != i; ++j)
- staticPath.push_back(AttrName(getName(*j, state, env)));
- staticPath.push_back(AttrName(getName(*j, state, env)));
- for (j = j + 1; j != attrPath.end(); ++j)
- staticPath.push_back(*j);
- throwEvalError("attribute ‘%1%’ missing, at %2%", showAttrPath(staticPath), pos);
- }
+ if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end())
+ throwEvalError("attribute ‘%1%’ missing, at %2%", name, pos);
}
vAttrs = j->value;
pos2 = j->pos;
@@ -812,7 +821,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
} catch (Error & e) {
if (pos2 && pos2->file != state.sDerivationNix)
addErrorPrefix(e, "while evaluating the attribute ‘%1%’ at %2%:\n",
- showAttrPath(attrPath), *pos2);
+ showAttrPath(state, env, attrPath), *pos2);
throw;
}