From 6ff2ce8caf6f5fa0134ab7c6fa9547226dad8bde Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Sat, 15 Jan 2022 19:17:40 -0800 Subject: [PATCH 1/3] Added result and .vscode to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) 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/ From 61f02f7f2082a1a012b6ae0e3d5c2edc3567c5b7 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Sat, 15 Jan 2022 19:36:07 -0800 Subject: [PATCH 2/3] Make queryJSON not bail immediately on an assertion or error --- src/nix-env/nix-env.cc | 58 ++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index f4647f43d..f95754599 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -911,36 +911,44 @@ static void queryJSON(Globals & globals, vector & elems, bool printOutP { JSONObject topObj(cout, true); for (auto & i : elems) { - JSONObject pkgObj = topObj.object(i.attrPath); + try { + if (i.hasFailed()) continue; - 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()); + JSONObject pkgObj = topObj.object(i.attrPath); - if (printOutPath) { - DrvInfo::Outputs outputs = i.queryOutputs(); - JSONObject outputObj = pkgObj.object("outputs"); - for (auto & j : outputs) { - outputObj.attr(j.first, j.second); - } - } + 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 (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 (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); + } + } + } + } catch (AssertionError & e) { + printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); + } catch (Error & e) { + printMsg(lvlError, "skipping derivation named '%1%' which gives an error '%2%'", i.queryName(), e.msg()); } } } From 8ba7a2d3a8283babea324d3f822c9e5b75a174b4 Mon Sep 17 00:00:00 2001 From: Farid Zakaria Date: Mon, 24 Jan 2022 19:12:13 -0800 Subject: [PATCH 3/3] Do not suppress errors in nix-env from feedback by Eelco --- src/nix-env/nix-env.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index f95754599..d2636abf7 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -948,7 +948,8 @@ static void queryJSON(Globals & globals, vector & elems, bool printOutP } catch (AssertionError & e) { printMsg(lvlTalkative, "skipping derivation named '%1%' which gives an assertion failure", i.queryName()); } catch (Error & e) { - printMsg(lvlError, "skipping derivation named '%1%' which gives an error '%2%'", i.queryName(), e.msg()); + e.addTrace(std::nullopt, "while querying the derivation named '%1%'", i.queryName()); + throw; } } }