mirror of
https://github.com/NixOS/nix.git
synced 2025-11-11 13:06:01 +01:00
libflake: add lock file path to invalid json error
Previously, when lock file contained invalid JSON nix reported a parser
error without specifying the file it came from.
This change adds flake.lock file path to the error message to avoid
confusion.
(cherry picked from commit e3873aa1a0)
This commit is contained in:
parent
63b9b932f4
commit
49b6766332
1 changed files with 7 additions and 2 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue