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

Commit dce6a49

Browse files
pgtedaviddias
authored andcommitted
fix: make offline error retain stack (#1056)
1 parent 844bf18 commit dce6a49

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/core/components/bitswap.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ module.exports = function bitswap (self) {
1010
return {
1111
wantlist: () => {
1212
if (!self.isOnline()) {
13-
throw OFFLINE_ERROR
13+
throw new Error(OFFLINE_ERROR)
1414
}
1515

1616
const list = self._bitswap.getWantlist()
1717
return formatWantlist(list)
1818
},
1919
stat: () => {
2020
if (!self.isOnline()) {
21-
throw OFFLINE_ERROR
21+
throw new Error(OFFLINE_ERROR)
2222
}
2323

2424
const stats = self._bitswap.stat()
@@ -29,7 +29,7 @@ module.exports = function bitswap (self) {
2929
},
3030
unwant: (key) => {
3131
if (!self.isOnline()) {
32-
throw OFFLINE_ERROR
32+
throw new Error(OFFLINE_ERROR)
3333
}
3434

3535
// TODO: implement when https://github.com/ipfs/js-ipfs-bitswap/pull/10 is merged

src/core/components/pubsub.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function pubsub (self) {
99
return {
1010
subscribe: (topic, options, handler, callback) => {
1111
if (!self.isOnline()) {
12-
throw OFFLINE_ERROR
12+
throw new Error(OFFLINE_ERROR)
1313
}
1414

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

4545
publish: promisify((topic, data, callback) => {
4646
if (!self.isOnline()) {
47-
return setImmediate(() => callback(OFFLINE_ERROR))
47+
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
4848
}
4949

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

5858
ls: promisify((callback) => {
5959
if (!self.isOnline()) {
60-
return setImmediate(() => callback(OFFLINE_ERROR))
60+
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
6161
}
6262

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

7070
peers: promisify((topic, callback) => {
7171
if (!self.isOnline()) {
72-
return setImmediate(() => callback(OFFLINE_ERROR))
72+
return setImmediate(() => callback(new Error(OFFLINE_ERROR)))
7373
}
7474

7575
const peers = Array.from(self._pubsub.peers.values())

src/core/components/swarm.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = function swarm (self) {
1515
}
1616

1717
if (!self.isOnline()) {
18-
return callback(OFFLINE_ERROR)
18+
return callback(new Error(OFFLINE_ERROR))
1919
}
2020

2121
const verbose = opts.v || opts.verbose
@@ -46,7 +46,7 @@ module.exports = function swarm (self) {
4646
// all the addrs we know
4747
addrs: promisify((callback) => {
4848
if (!self.isOnline()) {
49-
return callback(OFFLINE_ERROR)
49+
return callback(new Error(OFFLINE_ERROR))
5050
}
5151

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

5757
localAddrs: promisify((callback) => {
5858
if (!self.isOnline()) {
59-
return callback(OFFLINE_ERROR)
59+
return callback(new Error(OFFLINE_ERROR))
6060
}
6161

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

6565
connect: promisify((maddr, callback) => {
6666
if (!self.isOnline()) {
67-
return callback(OFFLINE_ERROR)
67+
return callback(new Error(OFFLINE_ERROR))
6868
}
6969

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

7777
disconnect: promisify((maddr, callback) => {
7878
if (!self.isOnline()) {
79-
return callback(OFFLINE_ERROR)
79+
return callback(new Error(OFFLINE_ERROR))
8080
}
8181

8282
if (typeof maddr === 'string') {

src/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
'use strict'
22

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

0 commit comments

Comments
 (0)