Skip to content

Commit

Permalink
Merge remote-tracking branch 'ArkEcosystem/core/develop' into verify-…
Browse files Browse the repository at this point in the history
…peer-state

* ArkEcosystem/core/develop:
  fix(core-p2p): return an empty array if the peers cache parsing fails (#2061)
  • Loading branch information
vasild committed Feb 4, 2019
2 parents 179cfb0 + ccf3647 commit eca24c0
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/core-p2p/src/utils/restore-peers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ export const restorePeers = (): any[] => {
return [];
}

const peers = JSON.parse(readFileSync(path, { encoding: "utf8" }));
const { value, error } = Joi.validate(peers, schema);
try {
const peers = JSON.parse(readFileSync(path, { encoding: "utf8" }));
const { value, error } = Joi.validate(peers, schema);

if (error) {
const logger = app.resolvePlugin<Logger.ILogger>("logger");
if (logger) {
logger.warn("Ignoring corrupt peers from cache.");
if (error) {
const logger = app.resolvePlugin<Logger.ILogger>("logger");
if (logger) {
logger.warn("Ignoring corrupt peers from cache.");
}
return [];
}

return value;
} catch (error) {
return [];
}

return value;
};

0 comments on commit eca24c0

Please sign in to comment.