diff --git a/packages/core-p2p/src/utils/restore-peers.ts b/packages/core-p2p/src/utils/restore-peers.ts index 86426e2605..4b605e9617 100644 --- a/packages/core-p2p/src/utils/restore-peers.ts +++ b/packages/core-p2p/src/utils/restore-peers.ts @@ -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"); - if (logger) { - logger.warn("Ignoring corrupt peers from cache."); + if (error) { + const logger = app.resolvePlugin("logger"); + if (logger) { + logger.warn("Ignoring corrupt peers from cache."); + } + return []; } + + return value; + } catch (error) { return []; } - - return value; };