about summary refs log tree commit diff
path: root/src/nix/search.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/search.cc')
-rw-r--r--src/nix/search.cc9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/nix/search.cc b/src/nix/search.cc
index 8aac06ad2cd3..970dcb9834b9 100644
--- a/src/nix/search.cc
+++ b/src/nix/search.cc
@@ -54,6 +54,8 @@ struct CmdSearch : SourceExprCommand, MixJSON
 
         auto jsonOut = json ? std::make_unique<JSONObject>(std::cout, true) : nullptr;
 
+        auto sToplevel = state->symbols.create("_toplevel");
+
         doExpr = [&](Value * v, std::string attrPath, bool toplevel) {
             debug("at attribute ‘%s’", attrPath);
 
@@ -123,7 +125,7 @@ struct CmdSearch : SourceExprCommand, MixJSON
                         if (j == attrs->end() || !state->forceBool(*j->value, *j->pos)) return;
                     }
 
-                    Bindings::iterator j = v->attrs->find(state->symbols.create("_toplevel"));
+                    Bindings::iterator j = v->attrs->find(sToplevel);
                     bool toplevel2 = j != v->attrs->end() && state->forceBool(*j->value, *j->pos);
 
                     for (auto & i : *v->attrs) {
@@ -134,6 +136,11 @@ struct CmdSearch : SourceExprCommand, MixJSON
                 }
 
             } catch (AssertionError & e) {
+            } catch (Error & e) {
+                if (!toplevel) {
+                    e.addPrefix(fmt("While evaluating the attribute ‘%s’:\n", attrPath));
+                    throw;
+                }
             }
         };