about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-01-07T12·43+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-01-07T12·43+0100
commit153a943de7c333470e2b7338a8edae4a8ae52181 (patch)
treee5371991d49910300e704e2309c29b1b72da94a7 /src/libexpr
parent6fec43ccb3ebaa979c95143ee49c857d22ac4abf (diff)
Show position info for failing <...> lookups
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.hh2
-rw-r--r--src/libexpr/parser.y8
-rw-r--r--src/libexpr/primops.cc2
3 files changed, 8 insertions, 4 deletions
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 78942927fd..ed648fba8d 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -169,7 +169,7 @@ public:
 
     /* Look up a file in the search path. */
     Path findFile(const string & path);
-    Path findFile(SearchPath & searchPath, const string & path);
+    Path findFile(SearchPath & searchPath, const string & path, const Pos & pos = noPos);
 
     /* Evaluate an expression to normal form, storing the result in
        value `v'. */
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index ff174815e7..7d877cd678 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -626,7 +626,7 @@ Path EvalState::findFile(const string & path)
 }
 
 
-Path EvalState::findFile(SearchPath & searchPath, const string & path)
+Path EvalState::findFile(SearchPath & searchPath, const string & path, const Pos & pos)
 {
     foreach (SearchPath::iterator, i, searchPath) {
         Path res;
@@ -641,7 +641,11 @@ Path EvalState::findFile(SearchPath & searchPath, const string & path)
         }
         if (pathExists(res)) return canonPath(res);
     }
-    throw ThrownError(format("file ‘%1%’ was not found in the Nix search path (add it using $NIX_PATH or -I)") % path);
+    format f = format(
+        "file ‘%1%’ was not found in the Nix search path (add it using $NIX_PATH or -I)"
+        + string(pos ? ", at %2%" : ""));
+    f.exceptions(boost::io::all_error_bits ^ boost::io::too_many_args_bit);
+    throw ThrownError(f % path % pos);
 }
 
 
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index cd7b287e29..119e71a049 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -775,7 +775,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
             % path % e.path % pos);
     }
 
-    mkPath(v, state.findFile(searchPath, path).c_str());
+    mkPath(v, state.findFile(searchPath, path, pos).c_str());
 }
 
 /* Read a directory (without . or ..) */