Skip to content

TypeError: cb is not a function #135

@Akuukis

Description

@Akuukis

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.

class MyCommsWrapper {
    ...
    call(methodName, args) {
        return new Promise((resolve, reject) => {
            try {
                const cb = (err, res) => err ? reject(err) : resolve(res)
                console.assert(typeof cb === 'function')
                this.socket.emit(methodName, JSON.stringify(args), cb);
            } catch(err) {
                console.log(err)  // <-- Here originates the logs below.
                throw err
            }
        });
    }
    ...
}
    TypeError: cb is not a function
        at afterWrite (_stream_writable.js:463:3)
        at onwrite (_stream_writable.js:454:7)
        at Socket._writeGeneric (net.js:777:5)
        at Socket._writev (net.js:782:8)
        at doWrite (_stream_writable.js:394:12)
        at clearBuffer (_stream_writable.js:500:5)
        at Socket.Writable.uncork (_stream_writable.js:312:7)
        at Sender.sendFrame (./node_modules/socketcluster-client/node_modules/ws/lib/sender.js:353:20)
        at Sender.send (./node_modules/socketcluster-client/node_modules/ws/lib/sender.js:272:12)
        at WebSocket.send (./node_modules/socketcluster-client/node_modules/ws/lib/websocket.js:354:18)

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions