Skip to content

Commit

Permalink
Merge pull request #2505 from planetarium/fix/planet-default
Browse files Browse the repository at this point in the history
planetary edge case handling
  • Loading branch information
Akamig authored Nov 21, 2024
2 parents f0ee343 + 0be2ae7 commit 10251cd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ async function initializeConfig() {

registry = await data.json();
if (registry === undefined) throw Error("Failed to parse registry.");
if (!Array.isArray(registry) || registry.length <= 0) {
throw Error("Registry is empty or invalid. No planets found.");
}

const planet = registry.find((v) => v.id === remoteConfig.Planet);
if (!planet) throw Error(`Planet failed to initialize: ${planet}`);
const planet =
registry.find((v) => v.id === remoteConfig.Planet) ??
(() => {
console.log(
"No matching PlanetID found in registry. Using the first planet.",
);
remoteConfig.Planet = registry[0].id;
return registry[0];
})();

remoteNode = await initializeNode(planet.rpcEndpoints, true);
console.log(registry);
Expand Down

0 comments on commit 10251cd

Please sign in to comment.