mirror of https://codeberg.org/pzp/pzp-db.git
reading empty ghosts should not raise error
This commit is contained in:
parent
748125b6e6
commit
05e16a7037
|
@ -123,9 +123,13 @@ class GhostDB {
|
|||
this.#path(tangleID),
|
||||
GhostDB.encodingOpts,
|
||||
(/** @type {any} */ err, /** @type {any} */ str) => {
|
||||
// Load Map
|
||||
/** @type {Map<string, number>} */
|
||||
let map;
|
||||
if (err && err.code === 'ENOENT') map = new Map()
|
||||
// prettier-ignore
|
||||
if (err) return cb(new Error('GhostDB.read() failed to read ghost file', { cause: err }))
|
||||
const map = this.#deserialize(str)
|
||||
else if (err) return cb(new Error('GhostDB.read() failed to read ghost file', { cause: err }))
|
||||
else map = this.#deserialize(str)
|
||||
|
||||
cb(null, map)
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ test('ghosts.add, ghosts.get, ghosts.getMinDepth', async (t) => {
|
|||
}
|
||||
const feedID = peer.db.feed.getID(account, 'post')
|
||||
|
||||
const ghosts0 = await p(peer.db.ghosts.get)(feedID)
|
||||
assert.deepEqual(ghosts0, [], 'no ghosts so far')
|
||||
|
||||
await p(peer.db.ghosts.add)({ msg: msgIDs[0], tangle: feedID, max: MAX })
|
||||
await p(peer.db.ghosts.add)({ msg: msgIDs[1], tangle: feedID, max: MAX })
|
||||
await p(peer.db.ghosts.add)({ msg: msgIDs[2], tangle: feedID, max: MAX })
|
||||
|
|
Loading…
Reference in New Issue