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

Commit

Permalink
fix: code review
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 3, 2018
1 parent 02071b1 commit cf0bbb7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
15 changes: 10 additions & 5 deletions src/core/ipns/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/ipns/routing/offline-datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OfflineDatastore {
}

// Marshal to libp2p record as the DHT does
let record = new Record(key, value)
const record = new Record(key, value)

this._repo.datastore.put(routingKey, record.serialize(), callback)
}
Expand Down
2 changes: 1 addition & 1 deletion test/core/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/go-ipfs-repo/datastore/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000017
MANIFEST-000021
Binary file not shown.
1 change: 1 addition & 0 deletions test/fixtures/go-ipfs-repo/datastore_spec
Original file line number Diff line number Diff line change
@@ -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"}

0 comments on commit cf0bbb7

Please sign in to comment.