Merge pull request #12942 from NixOS/mergify/bp/2.28-maintenance/pr-12936

libflake: add lock file path to invalid json error (backport #12936)
This commit is contained in:
Eelco Dolstra 2025-04-07 09:57:33 +02:00 committed by GitHub
commit e3a8e43600
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,
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);
if (version < 5 || version > 7)
throw Error("lock file '%s' has unsupported version %d", path, version);