diff --git a/src/core/ipns/republisher.js b/src/core/ipns/republisher.js index 7345dceebd..150cb313d7 100644 --- a/src/core/ipns/republisher.js +++ b/src/core/ipns/republisher.js @@ -100,7 +100,7 @@ class IpnsRepublisher { } // keychain needs pass to get the cryptographic keys - if (this._keychain && Boolean(pass)) { + if (pass) { this._keychain.listKeys((err, list) => { if (err) { log.error(err) diff --git a/src/core/ipns/resolver.js b/src/core/ipns/resolver.js index 8ea7480c7d..f9fb81ccd5 100644 --- a/src/core/ipns/resolver.js +++ b/src/core/ipns/resolver.js @@ -105,34 +105,27 @@ class IpnsResolver { this._routing.get(routingKey.toBuffer(), (err, res) => { if (err) { + if (err.code !== 'ERR_NOT_FOUND') { + const errMsg = `unexpected error getting the ipns record ${peerId.id}` + + log.error(errMsg) + return callback(errcode(new Error(errMsg), 'ERR_UNEXPECTED_ERROR_GETTING_RECORD')) + } const errMsg = `record requested was not found for ${name} (${routingKey}) in the network` log.error(errMsg) return callback(errcode(new Error(errMsg), 'ERR_NO_RECORD_FOUND')) } - if (!res) { - const errMsg = `record requested was empty for ${name} (${routingKey}) in the network` - - log.error(errMsg) - return callback(errcode(new Error(errMsg), 'ERR_EMPTY_RECORD_FOUND')) - } - - if (!Buffer.isBuffer(res)) { - const errMsg = `found ipns record that we couldn't convert to a value` - - log.error(errMsg) - return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_RECEIVED')) - } - let ipnsEntry - try { const record = Record.deserialize(res) ipnsEntry = ipns.unmarshal(record.value) } catch (err) { - log.error(err) - return callback(err) + const errMsg = `found ipns record that we couldn't convert to a value` + + log.error(errMsg) + return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_RECEIVED')) } ipns.extractPublicKey(peerId, ipnsEntry, (err, pubKey) => { diff --git a/src/core/ipns/routing/utils.js b/src/core/ipns/routing/utils.js index 8448d77346..baa9ac16aa 100644 --- a/src/core/ipns/routing/utils.js +++ b/src/core/ipns/routing/utils.js @@ -3,5 +3,5 @@ const multibase = require('multibase') module.exports.encodeBase32 = (buf) => { - return multibase.encode('base32', buf) + return multibase.encode('base32', buf).slice(1) // slice off multibase codec } diff --git a/test/core/name.js b/test/core/name.js index 768a1780ca..790aee384d 100644 --- a/test/core/name.js +++ b/test/core/name.js @@ -322,15 +322,15 @@ describe('name', function () { node.name.resolve(nodeId, { nocache: true }, (err, res) => { expect(err).to.exist() - expect(err.code).to.equal('ERR_NO_RECORD_FOUND') + expect(err.code).to.equal('ERR_UNEXPECTED_ERROR_GETTING_RECORD') stub.restore() done() }) }) }) - it('should publish and then fail to resolve if does not get any data', function (done) { - const stub = sinon.stub(node._ipns.resolver._routing, 'get').callsArgWith(1, undefined, undefined) + it('should publish and then fail to resolve if does not find the record', function (done) { + const stub = sinon.stub(node._ipns.resolver._routing, 'get').callsArgWith(1, { code: 'ERR_NOT_FOUND' }) node.name.publish(ipfsRef, { resolve: false }, (err, res) => { expect(err).to.not.exist() @@ -338,7 +338,7 @@ describe('name', function () { node.name.resolve(nodeId, { nocache: true }, (err, res) => { expect(err).to.exist() - expect(err.code).to.equal('ERR_EMPTY_RECORD_FOUND') + expect(err.code).to.equal('ERR_NO_RECORD_FOUND') stub.restore() done() })