diff --git a/src/core/ipns/publisher.js b/src/core/ipns/publisher.js index aa330ce053..2220d28174 100644 --- a/src/core/ipns/publisher.js +++ b/src/core/ipns/publisher.js @@ -182,10 +182,9 @@ class IpnsPublisher { return callback(err) } - this._routing.get(keys.routingKey, (err, res) => { + this._routing.get(keys.routingKey.toBuffer(), (err, res) => { if (err) { - log(`error when determining the last published IPNS record for ${peerId.id}`) - return callback(null, null) + return callback(err) } // unmarshal data @@ -206,7 +205,7 @@ class IpnsPublisher { const errMsg = `found ipns record that we couldn't convert to a value` log.error(errMsg) - return callback(null, null) + return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_DATA')) } callback(null, result) @@ -226,11 +225,17 @@ class IpnsPublisher { this._getPublished(peerId, getPublishedOptions, (err, record) => { if (err) { - return callback(err) + if (err.code !== 'ERR_NOT_FOUND') { + const errMsg = `unexpected error when determining the last published IPNS record for ${peerId.id}` + + log.error(errMsg) + return callback(errcode(new Error(errMsg), 'ERR_DETERMINING_PUBLISHED_RECORD')) + } } // Determinate the record sequence number let seqNumber = 0 + if (record && record.sequence !== undefined) { seqNumber = record.value.toString() !== value ? record.sequence + 1 : record.sequence } diff --git a/test/core/name.js b/test/core/name.js index 7aa11ecdfe..e43627ea94 100644 --- a/test/core/name.js +++ b/test/core/name.js @@ -340,7 +340,7 @@ describe('name', function () { node.name.publish(ipfsRef, { resolve: false }, (err, res) => { expect(err).to.exist() - expect(err.code).to.equal('ERR_UNEXPECTED_DATASTORE_RESPONSE') + expect(err.code).to.equal('ERR_DETERMINING_PUBLISHED_RECORD') stub.restore() done() diff --git a/test/fixtures/go-ipfs-repo/datastore/CURRENT b/test/fixtures/go-ipfs-repo/datastore/CURRENT index 056df57bb7..e60e1543b3 100644 --- a/test/fixtures/go-ipfs-repo/datastore/CURRENT +++ b/test/fixtures/go-ipfs-repo/datastore/CURRENT @@ -1 +1 @@ -MANIFEST-000017 +MANIFEST-000021 diff --git a/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000017 b/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000021 similarity index 91% rename from test/fixtures/go-ipfs-repo/datastore/MANIFEST-000017 rename to test/fixtures/go-ipfs-repo/datastore/MANIFEST-000021 index fb6bc82f41..dd5db1fec0 100644 Binary files a/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000017 and b/test/fixtures/go-ipfs-repo/datastore/MANIFEST-000021 differ diff --git a/test/fixtures/go-ipfs-repo/datastore_spec b/test/fixtures/go-ipfs-repo/datastore_spec new file mode 100644 index 0000000000..7bf9626c24 --- /dev/null +++ b/test/fixtures/go-ipfs-repo/datastore_spec @@ -0,0 +1 @@ +{"mounts":[{"mountpoint":"/blocks","path":"blocks","shardFunc":"/repo/flatfs/shard/v1/next-to-last/2","type":"flatfs"},{"mountpoint":"/","path":"datastore","type":"levelds"}],"type":"mount"} \ No newline at end of file