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

Uncaught TypeError: Cannot read property 'push' of null #1689

Closed
mccoysc opened this issue Nov 2, 2018 · 5 comments
Closed

Uncaught TypeError: Cannot read property 'push' of null #1689

mccoysc opened this issue Nov 2, 2018 · 5 comments

Comments

@mccoysc
Copy link

mccoysc commented Nov 2, 2018

await ipfs.ping("QmZ6YuHZUJd6k9hbJNaNUZBsWfwZGv62piZMU6oxHPBtDx")

collect.js:7 Uncaught TypeError: Cannot read property 'push' of null
at collect.js:7
at reduce.js:8
at drain.js:24
at f (index.js:84)
at Function.u [as push] (index.js:44)
at e.ping (ping-pull-stream.js:79)
at _getPeerInfo (index.js:339)
at s (get-peer-info.js:54)
at setImmediate.js:27
at setImmediate.js:40
at f (setImmediate.js:69)
at r (setImmediate.js:109)

i found the code like this(@ line 6 of node-modules/pull-stream/sinks/reduce.js):

module.exports = function reduce(reducer, acc, cb) {
if (!cb) cb = acc, acc = null
var sink = drain(function (data) {
acc = reducer(acc, data)
}, function (err) {
cb(err, acc)
})
if (arguments.length === 2)
return function (source) {
source(null, function (end, data) {
//if ended immediately, and no initial...
if (end) return cb(end === true ? null : end)
acc = data;
sink(source)
})
}
else
return sink
}

at some moment, "acc" would be set to "null",and the error caused by this resaon.
may be ,the code should be "if (!cb) cb = acc, acc = []"

@mccoysc
Copy link
Author

mccoysc commented Nov 2, 2018

jsipfs version 0.33.0

@mccoysc
Copy link
Author

mccoysc commented Nov 2, 2018

browser version in google chrome

@mccoysc
Copy link
Author

mccoysc commented Nov 2, 2018

and if i make the code "acc=[]",another error:

Uncaught TypeError: cb is not a function
at reduce.js:10
at drain.js:20
at f (index.js:84)
at c (index.js:68)
at Function.a [as end] (index.js:36)
at e.exports.o.on.e (ping-pull-stream.js:97)
at e.exports.r.emit (events.js:81)
at p.swarm.dial [as callback] (ping.js:30)
at a (dial.js:110)
at once.js:12
at f (waterfall.js:21)
at onlyOnce.js:12
at a (dial.js:160)
at once.js:12
at f (waterfall.js:21)
at onlyOnce.js:12

it meas that,in module "pull-stream",you can call “reduce(reducer,[],callback)” or “reduce(reducer,callback)” .
but in fact ,neighter of them.

@mccoysc
Copy link
Author

mccoysc commented Nov 2, 2018

if i change the node-modules/ipfs/src/core/componets/ping.js to the following:

module.exports = function ping(self) {
return function (peerId, opts, cb) {
return new Promise(function (resp, rej) {
function _cb() {
if (cb) {
return cb.apply(this, arguments);
}
if (arguments[0]) {
return rej(arguments[0]);
}
return resp(arguments[1]);
}
pull(self.pingPullStream(peerId, opts), pull.collect(_cb));
});
}
}

all is ok.

it seems that maybe the module "promisefy-es6" has some bugs

@alanshaw
Copy link
Member

This is the same error as the second issue reported in #1616 and was resolved by #1627

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants