1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 06:31:14 +02:00

Merge pull request #12936 from ajlekcahdp4/master

libflake: add lock file path to invalid json error
This commit is contained in:
mergify[bot] 2025-04-06 23:32:50 +00:00 committed by GitHub
commit 1dc7e6c4dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -108,8 +108,13 @@ LockFile::LockFile(
const fetchers::Settings & fetchSettings, const fetchers::Settings & fetchSettings,
std::string_view contents, std::string_view path) std::string_view contents, std::string_view path)
{ {
auto json = nlohmann::json::parse(contents); auto json = [=] {
try {
return nlohmann::json::parse(contents);
} catch (const nlohmann::json::parse_error & e) {
throw Error("Could not parse '%s': %s", path, e.what());
}
}();
auto version = json.value("version", 0); auto version = json.value("version", 0);
if (version < 5 || version > 7) if (version < 5 || version > 7)
throw Error("lock file '%s' has unsupported version %d", path, version); throw Error("lock file '%s' has unsupported version %d", path, version);