From 2f885fd8076448589ba6cc825ee291d5517637a2 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 14 Sep 2023 13:55:50 +0300 Subject: [PATCH] add a try catch, plus minor renaming --- lib/index.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/index.js b/lib/index.js index 5e32cfa..f9c7bfe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -183,13 +183,13 @@ module.exports = { /** * @private - * @param {string} rootID - * @param {Msg} root + * @param {string} mootID + * @param {Msg} moot */ - function learnRecordRoot(rootID, root) { - const subdomain = toSubdomain(root.metadata.domain) - const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(rootID) - tangle.add(rootID, root) + function learnRecordMoot(mootID, moot) { + const subdomain = toSubdomain(moot.metadata.domain) + const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID) + tangle.add(mootID, moot) tangles.set(subdomain, tangle) } @@ -200,9 +200,9 @@ module.exports = { */ function learnRecordUpdate(msgID, msg) { const { account, domain } = msg.metadata - const rootID = MsgV3.getMootID(account, domain) + const mootID = MsgV3.getMootID(account, domain) const subdomain = toSubdomain(domain) - const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(rootID) + const tangle = tangles.get(subdomain) ?? new MsgV3.Tangle(mootID) tangle.add(msgID, msg) tangles.set(subdomain, tangle) @@ -231,7 +231,7 @@ module.exports = { function maybeLearnAboutRecord(msgID, msg) { if (msg.metadata.account !== accountID) return if (isValidRecordMoot(msg)) { - learnRecordRoot(msgID, msg) + learnRecordMoot(msgID, msg) return } if (isValidRecordMsg(msg)) { @@ -317,9 +317,13 @@ module.exports = { } cancelOnRecordAdded = peer.db.onRecordAdded( (/** @type {RecPresent} */ rec) => { - if (!rec.msg) return - maybeLearnAboutRecord(rec.id, rec.msg) - }) + try { + maybeLearnAboutRecord(rec.id, rec.msg) + } catch (err) { + console.error(err) + } + } + ) resolve() cb() })