diff options
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | src/nix-env/nix-env.cc | 61 |
2 files changed, 39 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore index 2889a56eb..4b290425a 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,7 @@ GTAGS compile_commands.json nix-rust/target + +result + +.vscode/ 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; } } } |