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

Commit cf0bbb7

Browse files
committed
fix: code review
1 parent 02071b1 commit cf0bbb7

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

src/core/ipns/publisher.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ class IpnsPublisher {
182182
return callback(err)
183183
}
184184

185-
this._routing.get(keys.routingKey, (err, res) => {
185+
this._routing.get(keys.routingKey.toBuffer(), (err, res) => {
186186
if (err) {
187-
log(`error when determining the last published IPNS record for ${peerId.id}`)
188-
return callback(null, null)
187+
return callback(err)
189188
}
190189

191190
// unmarshal data
@@ -206,7 +205,7 @@ class IpnsPublisher {
206205
const errMsg = `found ipns record that we couldn't convert to a value`
207206

208207
log.error(errMsg)
209-
return callback(null, null)
208+
return callback(errcode(new Error(errMsg), 'ERR_INVALID_RECORD_DATA'))
210209
}
211210

212211
callback(null, result)
@@ -226,11 +225,17 @@ class IpnsPublisher {
226225

227226
this._getPublished(peerId, getPublishedOptions, (err, record) => {
228227
if (err) {
229-
return callback(err)
228+
if (err.code !== 'ERR_NOT_FOUND') {
229+
const errMsg = `unexpected error when determining the last published IPNS record for ${peerId.id}`
230+
231+
log.error(errMsg)
232+
return callback(errcode(new Error(errMsg), 'ERR_DETERMINING_PUBLISHED_RECORD'))
233+
}
230234
}
231235

232236
// Determinate the record sequence number
233237
let seqNumber = 0
238+
234239
if (record && record.sequence !== undefined) {
235240
seqNumber = record.value.toString() !== value ? record.sequence + 1 : record.sequence
236241
}

src/core/ipns/routing/offline-datastore.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class OfflineDatastore {
5050
}
5151

5252
// Marshal to libp2p record as the DHT does
53-
let record = new Record(key, value)
53+
const record = new Record(key, value)
5454

5555
this._repo.datastore.put(routingKey, record.serialize(), callback)
5656
}

test/core/name.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe('name', function () {
340340

341341
node.name.publish(ipfsRef, { resolve: false }, (err, res) => {
342342
expect(err).to.exist()
343-
expect(err.code).to.equal('ERR_UNEXPECTED_DATASTORE_RESPONSE')
343+
expect(err.code).to.equal('ERR_DETERMINING_PUBLISHED_RECORD')
344344

345345
stub.restore()
346346
done()
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
MANIFEST-000017
1+
MANIFEST-000021
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"mounts":[{"mountpoint":"/blocks","path":"blocks","shardFunc":"/repo/flatfs/shard/v1/next-to-last/2","type":"flatfs"},{"mountpoint":"/","path":"datastore","type":"levelds"}],"type":"mount"}

0 commit comments

Comments
 (0)