Improve error message
This commit is contained in:
parent
9f3eb56b46
commit
5badc8f975
2 changed files with 25 additions and 19 deletions
|
@ -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;
|
unsigned long nrLookups = 0;
|
||||||
|
|
||||||
void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
|
@ -791,16 +808,8 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.forceAttrs(*vAttrs, pos);
|
state.forceAttrs(*vAttrs, pos);
|
||||||
if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) {
|
if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end())
|
||||||
AttrPath staticPath;
|
throwEvalError("attribute ‘%1%’ missing, at %2%", name, pos);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
vAttrs = j->value;
|
vAttrs = j->value;
|
||||||
pos2 = j->pos;
|
pos2 = j->pos;
|
||||||
|
@ -812,7 +821,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
if (pos2 && pos2->file != state.sDerivationNix)
|
if (pos2 && pos2->file != state.sDerivationNix)
|
||||||
addErrorPrefix(e, "while evaluating the attribute ‘%1%’ at %2%:\n",
|
addErrorPrefix(e, "while evaluating the attribute ‘%1%’ at %2%:\n",
|
||||||
showAttrPath(attrPath), *pos2);
|
showAttrPath(state, env, attrPath), *pos2);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -200,15 +200,12 @@ string showAttrPath(const AttrPath & attrPath)
|
||||||
{
|
{
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
foreach (AttrPath::const_iterator, i, attrPath) {
|
for (auto & i : attrPath) {
|
||||||
if (!first)
|
if (!first) out << '.'; else first = false;
|
||||||
out << '.';
|
if (i.symbol.set())
|
||||||
|
out << i.symbol;
|
||||||
else
|
else
|
||||||
first = false;
|
out << "\"${" << *i.expr << "}\"";
|
||||||
if (i->symbol.set())
|
|
||||||
out << i->symbol;
|
|
||||||
else
|
|
||||||
out << "\"${" << *i->expr << "}\"";
|
|
||||||
}
|
}
|
||||||
return out.str();
|
return out.str();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue