aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-04-02 19:09:17 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-04-02 19:09:17 +0200
commit485a87f22f96498727deab044fc74931164a1acd (patch)
treee2d7522c642ceff8a7e1d373b967118762f139a4
parenta6ff66b658b61aef80d936f0183447fe4cb46000 (diff)
Don't barf on registry parse errors
-rw-r--r--src/libfetchers/registry.cc73
1 files changed, 39 insertions, 34 deletions
diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc
index e452e8497..77e5da741 100644
--- a/src/libfetchers/registry.cc
+++ b/src/libfetchers/registry.cc
@@ -17,46 +17,51 @@ std::shared_ptr<Registry> Registry::read(
if (!pathExists(path))
return std::make_shared<Registry>(type);
- auto json = nlohmann::json::parse(readFile(path));
-
- auto version = json.value("version", 0);
-
- // FIXME: remove soon
- 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), {}});
+ try {
+
+ auto json = nlohmann::json::parse(readFile(path));
+
+ auto version = json.value("version", 0);
+
+ // FIXME: remove soon
+ 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) {
- 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);
+ 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()
+ });
}
- 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);
+ 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());
+ }
return registry;
}