aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/attr-path.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr/attr-path.cc')
-rw-r--r--src/libexpr/attr-path.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/libexpr/attr-path.cc b/src/libexpr/attr-path.cc
index 06b472d8b..4545bfd72 100644
--- a/src/libexpr/attr-path.cc
+++ b/src/libexpr/attr-path.cc
@@ -32,7 +32,7 @@ static Strings parseAttrPath(const string & s)
}
-Value * findAlongAttrPath(EvalState & state, const string & attrPath,
+std::pair<Value *, Pos> findAlongAttrPath(EvalState & state, const string & attrPath,
Bindings & autoArgs, Value & vIn)
{
Strings tokens = parseAttrPath(attrPath);
@@ -41,6 +41,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
Error(format("attribute selection path '%1%' does not match expression") % attrPath);
Value * v = &vIn;
+ Pos pos = noPos;
for (auto & attr : tokens) {
@@ -70,8 +71,9 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
Bindings::iterator a = v->attrs->find(state.symbols.create(attr));
if (a == v->attrs->end())
- throw Error(format("attribute '%1%' in selection path '%2%' not found") % attr % attrPath);
+ throw AttrPathNotFound("attribute '%1%' in selection path '%2%' not found", attr, attrPath);
v = &*a->value;
+ pos = *a->pos;
}
else if (apType == apIndex) {
@@ -82,14 +84,15 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
% attrPath % showType(*v));
if (attrIndex >= v->listSize())
- throw Error(format("list index %1% in selection path '%2%' is out of range") % attrIndex % attrPath);
+ throw AttrPathNotFound("list index %1% in selection path '%2%' is out of range", attrIndex, attrPath);
v = v->listElems()[attrIndex];
+ pos = noPos;
}
}
- return v;
+ return {v, pos};
}
@@ -98,9 +101,9 @@ Pos findDerivationFilename(EvalState & state, Value & v, std::string what)
Value * v2;
try {
auto dummyArgs = state.allocBindings(0);
- v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v);
+ v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v).first;
} catch (Error &) {
- throw Error("package '%s' has no source location information", what);
+ throw NoPositionInfo("package '%s' has no source location information", what);
}
// FIXME: is it possible to extract the Pos object instead of doing this