aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-01-25 12:44:20 +0100
committerGitHub <noreply@github.com>2022-01-25 12:44:20 +0100
commita04a66c19659a092821877ff41a8380118ff7376 (patch)
tree03f4b83a2ad68c8b1afce8910c3d0cf165af5cb7
parenta5bdffaae9b70ab3a86c1655126427fb092617c4 (diff)
parent8ba7a2d3a8283babea324d3f822c9e5b75a174b4 (diff)
Merge pull request #5922 from fzakaria/fzakaria/json-ignore-assertion
Add try/catch to queryJSON for assertion and errors
-rw-r--r--.gitignore4
-rw-r--r--src/nix-env/nix-env.cc61
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;
}
}
}