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

Commit

Permalink
fix: make offline error retain stack (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and daviddias committed Nov 4, 2017
1 parent 844bf18 commit dce6a49
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/core/components/bitswap.js
Expand Up @@ -10,15 +10,15 @@ module.exports = function bitswap (self) {
return {
wantlist: () => {
if (!self.isOnline()) {
throw OFFLINE_ERROR
throw new Error(OFFLINE_ERROR)
}

const list = self._bitswap.getWantlist()
return formatWantlist(list)
},
stat: () => {
if (!self.isOnline()) {
throw OFFLINE_ERROR
throw new Error(OFFLINE_ERROR)
}

const stats = self._bitswap.stat()
Expand All @@ -29,7 +29,7 @@ module.exports = function bitswap (self) {
},
unwant: (key) => {
if (!self.isOnline()) {
throw OFFLINE_ERROR
throw new Error(OFFLINE_ERROR)
}

// TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged
Expand Down
8 changes: 4 additions & 4 deletions src/core/components/pubsub.js
Expand Up @@ -9,7 +9,7 @@ module.exports = function pubsub (self) {
return {
subscribe: (topic, options, handler, callback) => {
if (!self.isOnline()) {
throw OFFLINE_ERROR
throw new Error(OFFLINE_ERROR)
}

if (typeof options === 'function') {
Expand Down Expand Up @@ -44,7 +44,7 @@ module.exports = function pubsub (self) {

publish: promisify((topic, data, callback) => {
if (!self.isOnline()) {
return setImmediate(() => callback(OFFLINE_ERROR))
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
}

if (!Buffer.isBuffer(data)) {
Expand All @@ -57,7 +57,7 @@ module.exports = function pubsub (self) {

ls: promisify((callback) => {
if (!self.isOnline()) {
return setImmediate(() => callback(OFFLINE_ERROR))
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
}

const subscriptions = Array.from(
Expand All @@ -69,7 +69,7 @@ module.exports = function pubsub (self) {

peers: promisify((topic, callback) => {
if (!self.isOnline()) {
return setImmediate(() => callback(OFFLINE_ERROR))
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
}

const peers = Array.from(self._pubsub.peers.values())
Expand Down
10 changes: 5 additions & 5 deletions src/core/components/swarm.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function swarm (self) {
}

if (!self.isOnline()) {
return callback(OFFLINE_ERROR)
return callback(new Error(OFFLINE_ERROR))
}

const verbose = opts.v || opts.verbose
Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = function swarm (self) {
// all the addrs we know
addrs: promisify((callback) => {
if (!self.isOnline()) {
return callback(OFFLINE_ERROR)
return callback(new Error(OFFLINE_ERROR))
}

const peers = values(self._peerInfoBook.getAll())
Expand All @@ -56,15 +56,15 @@ module.exports = function swarm (self) {

localAddrs: promisify((callback) => {
if (!self.isOnline()) {
return callback(OFFLINE_ERROR)
return callback(new Error(OFFLINE_ERROR))
}

callback(null, self._libp2pNode.peerInfo.multiaddrs.toArray())
}),

connect: promisify((maddr, callback) => {
if (!self.isOnline()) {
return callback(OFFLINE_ERROR)
return callback(new Error(OFFLINE_ERROR))
}

if (typeof maddr === 'string') {
Expand All @@ -76,7 +76,7 @@ module.exports = function swarm (self) {

disconnect: promisify((maddr, callback) => {
if (!self.isOnline()) {
return callback(OFFLINE_ERROR)
return callback(new Error(OFFLINE_ERROR))
}

if (typeof maddr === 'string') {
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.js
@@ -1,3 +1,3 @@
'use strict'

exports.OFFLINE_ERROR = new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.')
exports.OFFLINE_ERROR = 'This command must be run in online mode. Try running \'ipfs daemon\' first.'

0 comments on commit dce6a49

Please sign in to comment.