-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
TypeError: cb is not a function #135
Comments
That was on node v8.16.2. For node v10.17.0 error is different:
|
I'm not sure what could be causing the first error maybe related to the Node.js version and the use of fat arrow function syntax. The second error |
@jondubois Thanks for insights! The only difference between both cases we underlying nodejs version for client, no code was changed. I'd rule out fat arrow syntax, because for other near-identical calls it works, and I use arrows everywhere.
Sounds interesting - would you please advice how to debug (e.g. inject console.log somewhere) to confirm this? I've got both client and server sides hosted locally. |
Is the new error In any case you can try logging the On the sender/emitter side, could make a wrapper function around the callback which you pass to the emit method to check if/when it is called twice. |
The error |
See in stacktraces that three last lines are equal, but other's are not. Furthermore, I put a
Here you go. Is there anything suspicious?
N/A, see next answer
My callback is not called at all. See the snippet - it throws error synchronously. To double confirm, on server I don't see that request logged (first line of handler function is logging). |
@jondubois Thanks for the feedback. I looked into this problem from browser environment, and still the same event name
// Client snippet
this.socket.on('message', (msg) => this.log.warn(`event<"onMessage">:`, msg))
this.socket.on('error', (err) => this.log.warn(`event<"onError">:`, err))
this.log.warn(methodName, 'trigger')
this.socket.emit(methodName, JSON.stringify(args), (err, res) => {
if(!err) {
resolve(res)
} else {
this.log.warn(methodName, err)
reject(err)
}
}); // Server snippet
this.socket.on(methodName, (data, cb) => {
console.log(`called ${methodName}`)
try {
const result = 'lol' // server-side logic simplified.
cb(null, result);
console.log(`returned ${methodName}`)
}
catch (err) {
cb(JSON.stringify(err));
}
})); I hope this is enough concrete feedback for you to have some insights. Here's what I tried but none changed the behavior:
Perhaps both of cases are unrelated, but suspiciously these problems are exclusively with call only. Here's a clear formulation of the problem: server returns value (and browser network tab confirms it received) but EDIT: added more logs, updated log timestamps. |
I refactored to asyngual, but it behaves just the same as in the last comment. What else can I try? |
Problem
I've stumbled upon non-flaky but random bug - I have hundreds of similar calls, but only for few of them the bug applies. See below the code snippet and error.
Expected behavior
I'd expect it to just work, or at least give more informative error how to fix it.
I'm clueless how the callback function created exactly the same way, and asserted to be a function, may sometimes be an function and sometimes not. Also did some digging along stack trace to no avail.
Details
Please advice how to debug this in first place and what other details would be useful.
The text was updated successfully, but these errors were encountered: