aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2022-08-22 14:15:31 +0200
committerGitHub <noreply@github.com>2022-08-22 14:15:31 +0200
commit9ddef9f0be811277c76c1c2bd126cac7de4eaa35 (patch)
tree8ee3a89d349b0c8fb99604a130c2d70f786fb847 /src
parent33aca20616adb872dfab1b3852fe58b948783cd2 (diff)
parent7535ee345da6c0aea1dd81e7de7725b37d8bf8a1 (diff)
Merge pull request #6923 from ncfavier/nix-env-incomplete-json
Avoid producing incomplete JSON
Diffstat (limited to 'src')
-rw-r--r--src/libutil/json.cc6
-rw-r--r--src/nix-env/nix-env.cc4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/libutil/json.cc b/src/libutil/json.cc
index abe0e6e74..2f9e97ff5 100644
--- a/src/libutil/json.cc
+++ b/src/libutil/json.cc
@@ -193,7 +193,11 @@ JSONObject JSONPlaceholder::object()
JSONPlaceholder::~JSONPlaceholder()
{
- assert(!first || std::uncaught_exceptions());
+ if (first) {
+ assert(std::uncaught_exceptions());
+ if (state->stack != 0)
+ write(nullptr);
+ }
}
}
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index a69d3700d..fdd66220a 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -940,12 +940,12 @@ static void queryJSON(Globals & globals, std::vector<DrvInfo> & elems, bool prin
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);
+ metaObj.attr(j, nullptr);
} else {
+ auto placeholder = metaObj.placeholder(j);
PathSet context;
printValueAsJSON(*globals.state, true, *v, noPos, placeholder, context);
}