diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-07-19 16:06:10 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-07-20 13:33:13 +0200 |
commit | 57a30e101b36a064f09619bf4a3f0b8a3fdcdcad (patch) | |
tree | a9be7e2f1fc773ee7944d58be9b6593e26a10e88 /src/nix/search.cc | |
parent | fc3568e2633bf3faa234509cfc6034be95f10b6e (diff) |
nix search: Ignore top-level eval errors
$NIX_PATH may contain elements that don't evaluate to an attrset (like
"nixos-config"), so ignore those.
Diffstat (limited to 'src/nix/search.cc')
-rw-r--r-- | src/nix/search.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/nix/search.cc b/src/nix/search.cc index 8aac06ad2..970dcb983 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; + } } }; |