Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit a66deba

Browse files
committed
refactor: fix review
1 parent fa1d79c commit a66deba

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

src/core/ipns/republisher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class IpnsRepublisher {
100100
}
101101

102102
// keychain needs pass to get the cryptographic keys
103-
if (this._keychain && Boolean(pass)) {
103+
if (pass) {
104104
this._keychain.listKeys((err, list) => {
105105
if (err) {
106106
log.error(err)

src/core/ipns/resolver.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,34 +105,28 @@ class IpnsResolver {
105105

106106
this._routing.get(routingKey.toBuffer(), (err, res) => {
107107
if (err) {
108-
const errMsg = `record requested was not found for ${name} (${routingKey}) in the network`
108+
if (err.code !== 'ERR_NOT_FOUND') {
109+
const errMsg = `unexpected error getting the ipns record ${peerId.id}`
109110

110-
log.error(errMsg)
111-
return callback(errcode(new Error(errMsg), 'ERR_NO_RECORD_FOUND'))
112-
}
113-
114-
if (!res) {
115-
const errMsg = `record requested was empty for ${name} (${routingKey}) in the network`
111+
log.error(errMsg)
112+
return callback(errcode(new Error(errMsg), 'ERR_UNEXPECTED_ERROR_GETTING_RECORD'))
113+
} else {
114+
const errMsg = `record requested was not found for ${name} (${routingKey}) in the network`
116115

117-
log.error(errMsg)
118-
return callback(errcode(new Error(errMsg), 'ERR_EMPTY_RECORD_FOUND'))
119-
}
120-
121-
if (!Buffer.isBuffer(res)) {
122-
const errMsg = `found ipns record that we couldn't convert to a value`
123-
124-
log.error(errMsg)
125-
return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_RECEIVED'))
116+
log.error(errMsg)
117+
return callback(errcode(new Error(errMsg), 'ERR_NO_RECORD_FOUND'))
118+
}
126119
}
127120

128121
let ipnsEntry
129-
130122
try {
131123
const record = Record.deserialize(res)
132124
ipnsEntry = ipns.unmarshal(record.value)
133125
} catch (err) {
134-
log.error(err)
135-
return callback(err)
126+
const errMsg = `found ipns record that we couldn't convert to a value`
127+
128+
log.error(errMsg)
129+
return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_RECEIVED'))
136130
}
137131

138132
ipns.extractPublicKey(peerId, ipnsEntry, (err, pubKey) => {

src/core/ipns/routing/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
const multibase = require('multibase')
44

55
module.exports.encodeBase32 = (buf) => {
6-
return multibase.encode('base32', buf)
6+
return multibase.encode('base32', buf).slice(1) // slice off multibase codec
77
}

test/core/name.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,23 +322,23 @@ describe('name', function () {
322322

323323
node.name.resolve(nodeId, { nocache: true }, (err, res) => {
324324
expect(err).to.exist()
325-
expect(err.code).to.equal('ERR_NO_RECORD_FOUND')
325+
expect(err.code).to.equal('ERR_UNEXPECTED_ERROR_GETTING_RECORD')
326326
stub.restore()
327327
done()
328328
})
329329
})
330330
})
331331

332-
it('should publish and then fail to resolve if does not get any data', function (done) {
333-
const stub = sinon.stub(node._ipns.resolver._routing, 'get').callsArgWith(1, undefined, undefined)
332+
it('should publish and then fail to resolve if does not find the record', function (done) {
333+
const stub = sinon.stub(node._ipns.resolver._routing, 'get').callsArgWith(1, { code: 'ERR_NOT_FOUND' })
334334

335335
node.name.publish(ipfsRef, { resolve: false }, (err, res) => {
336336
expect(err).to.not.exist()
337337
expect(res).to.exist()
338338

339339
node.name.resolve(nodeId, { nocache: true }, (err, res) => {
340340
expect(err).to.exist()
341-
expect(err.code).to.equal('ERR_EMPTY_RECORD_FOUND')
341+
expect(err.code).to.equal('ERR_NO_RECORD_FOUND')
342342
stub.restore()
343343
done()
344344
})

0 commit comments

Comments
 (0)