Don't barf on registry parse errors
This commit is contained in:
parent
a6ff66b658
commit
485a87f22f
|
@ -17,47 +17,52 @@ std::shared_ptr<Registry> Registry::read(
|
||||||
if (!pathExists(path))
|
if (!pathExists(path))
|
||||||
return std::make_shared<Registry>(type);
|
return std::make_shared<Registry>(type);
|
||||||
|
|
||||||
auto json = nlohmann::json::parse(readFile(path));
|
try {
|
||||||
|
|
||||||
auto version = json.value("version", 0);
|
auto json = nlohmann::json::parse(readFile(path));
|
||||||
|
|
||||||
// FIXME: remove soon
|
auto version = json.value("version", 0);
|
||||||
if (version == 1) {
|
|
||||||
auto flakes = json["flakes"];
|
|
||||||
for (auto i = flakes.begin(); i != flakes.end(); ++i) {
|
|
||||||
auto url = i->value("url", i->value("uri", ""));
|
|
||||||
if (url.empty())
|
|
||||||
throw Error("flake registry '%s' lacks a 'url' attribute for entry '%s'",
|
|
||||||
path, i.key());
|
|
||||||
registry->entries.push_back(
|
|
||||||
{inputFromURL(i.key()), inputFromURL(url), {}});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (version == 2) {
|
// FIXME: remove soon
|
||||||
for (auto & i : json["flakes"]) {
|
if (version == 1) {
|
||||||
auto toAttrs = jsonToAttrs(i["to"]);
|
auto flakes = json["flakes"];
|
||||||
Attrs extraAttrs;
|
for (auto i = flakes.begin(); i != flakes.end(); ++i) {
|
||||||
auto j = toAttrs.find("dir");
|
auto url = i->value("url", i->value("uri", ""));
|
||||||
if (j != toAttrs.end()) {
|
if (url.empty())
|
||||||
extraAttrs.insert(*j);
|
throw Error("flake registry '%s' lacks a 'url' attribute for entry '%s'",
|
||||||
toAttrs.erase(j);
|
path, i.key());
|
||||||
|
registry->entries.push_back(
|
||||||
|
{inputFromURL(i.key()), inputFromURL(url), {}});
|
||||||
}
|
}
|
||||||
auto exact = i.find("exact");
|
|
||||||
registry->entries.push_back(
|
|
||||||
Entry {
|
|
||||||
.from = inputFromAttrs(jsonToAttrs(i["from"])),
|
|
||||||
.to = inputFromAttrs(toAttrs),
|
|
||||||
.extraAttrs = extraAttrs,
|
|
||||||
.exact = exact != i.end() && exact.value()
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (version == 2) {
|
||||||
|
for (auto & i : json["flakes"]) {
|
||||||
|
auto toAttrs = jsonToAttrs(i["to"]);
|
||||||
|
Attrs extraAttrs;
|
||||||
|
auto j = toAttrs.find("dir");
|
||||||
|
if (j != toAttrs.end()) {
|
||||||
|
extraAttrs.insert(*j);
|
||||||
|
toAttrs.erase(j);
|
||||||
|
}
|
||||||
|
auto exact = i.find("exact");
|
||||||
|
registry->entries.push_back(
|
||||||
|
Entry {
|
||||||
|
.from = inputFromAttrs(jsonToAttrs(i["from"])),
|
||||||
|
.to = inputFromAttrs(toAttrs),
|
||||||
|
.extraAttrs = extraAttrs,
|
||||||
|
.exact = exact != i.end() && exact.value()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
throw Error("flake registry '%s' has unsupported version %d", path, version);
|
||||||
|
|
||||||
|
} catch (nlohmann::json::exception & e) {
|
||||||
|
warn("cannot parse flake registry '%s': %s", path, e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
|
||||||
throw Error("flake registry '%s' has unsupported version %d", path, version);
|
|
||||||
|
|
||||||
|
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue