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

make offline error retain stack #1056

Merged
merged 1 commit into from
Nov 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/components/bitswap.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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.'