1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-21 09:49:36 +01:00

Convert Realisation JSON logic to standard style

No behavior is changed, just:

- Declare a canonical `nlohmnan::json::adl_serializer`

- Use `json-utils.hh` to shorten code without getting worse error
  messages.

Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
John Ericson 2025-09-17 18:14:12 -04:00
parent 6389f65d63
commit 91593a237f
7 changed files with 73 additions and 61 deletions

View file

@ -304,10 +304,15 @@ public:
if (queryRealisation.isNull(0))
return {oInvalid, 0};
auto realisation = std::make_shared<Realisation>(
Realisation::fromJSON(nlohmann::json::parse(queryRealisation.getStr(0)), "Local disk cache"));
return {oValid, realisation};
try {
return {
oValid,
std::make_shared<Realisation>(nlohmann::json::parse(queryRealisation.getStr(0))),
};
} catch (Error & e) {
e.addTrace({}, "while parsing the local disk cache");
throw;
}
});
}
@ -349,7 +354,8 @@ public:
auto & cache(getCache(*state, uri));
state->insertRealisation.use()(cache.id)(realisation.id.to_string())(realisation.toJSON().dump())(time(0))
state->insertRealisation
.use()(cache.id)(realisation.id.to_string())(static_cast<nlohmann::json>(realisation).dump())(time(0))
.exec();
});
}