diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-01-25 12:44:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-25 12:44:20 +0100 |
commit | a04a66c19659a092821877ff41a8380118ff7376 (patch) | |
tree | 03f4b83a2ad68c8b1afce8910c3d0cf165af5cb7 /src | |
parent | a5bdffaae9b70ab3a86c1655126427fb092617c4 (diff) | |
parent | 8ba7a2d3a8283babea324d3f822c9e5b75a174b4 (diff) |
Merge pull request #5922 from fzakaria/fzakaria/json-ignore-assertion
Add try/catch to queryJSON for assertion and errors
Diffstat (limited to 'src')
-rw-r--r-- | src/nix-env/nix-env.cc | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index f4647f43d..d2636abf7 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -911,36 +911,45 @@ static void queryJSON(Globals & globals, vector<DrvInfo> & elems, bool printOutP { JSONObject topObj(cout, true); for (auto & i : elems) { - JSONObject pkgObj = topObj.object(i.attrPath); - - auto drvName = DrvName(i.queryName()); - pkgObj.attr("name", drvName.fullName); - pkgObj.attr("pname", drvName.name); - pkgObj.attr("version", drvName.version); - pkgObj.attr("system", i.querySystem()); - - if (printOutPath) { - DrvInfo::Outputs outputs = i.queryOutputs(); - JSONObject outputObj = pkgObj.object("outputs"); - for (auto & j : outputs) { - outputObj.attr(j.first, j.second); + try { + if (i.hasFailed()) continue; + + JSONObject pkgObj = topObj.object(i.attrPath); + + auto drvName = DrvName(i.queryName()); + pkgObj.attr("name", drvName.fullName); + pkgObj.attr("pname", drvName.name); + pkgObj.attr("version", drvName.version); + pkgObj.attr("system", i.querySystem()); + + if (printOutPath) { + DrvInfo::Outputs outputs = i.queryOutputs(); + JSONObject outputObj = pkgObj.object("outputs"); + for (auto & j : outputs) { + outputObj.attr(j.first, j.second); + } } - } - if (printMeta) { - JSONObject metaObj = pkgObj.object("meta"); - StringSet metaNames = i.queryMetaNames(); - for (auto & j : metaNames) { - auto placeholder = metaObj.placeholder(j); - Value * v = i.queryMeta(j); - if (!v) { - printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j); - placeholder.write(nullptr); - } else { - PathSet context; - printValueAsJSON(*globals.state, true, *v, noPos, placeholder, context); + if (printMeta) { + JSONObject metaObj = pkgObj.object("meta"); + StringSet metaNames = i.queryMetaNames(); + for (auto & j : metaNames) { + auto placeholder = metaObj.placeholder(j); + Value * v = i.queryMeta(j); + if (!v) { + printError("derivation '%s' has invalid meta attribute '%s'", i.queryName(), j); + placeholder.write(nullptr); + } else { + PathSet context; + printValueAsJSON(*globals.state, true, *v, noPos, placeholder, context); + } } } + } catch (AssertionError & e) { + printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); + } catch (Error & e) { + e.addTrace(std::nullopt, "while querying the derivation named '%1%'", i.queryName()); + throw; } } } |