Skip to content

Delayed exception on undefined Callback in rest-adapter.js #286

Description

@jbcpollak

I have Loopback code that uses the loopback-connector-remote and does this:

Model.findById(function(err, model) {
    // my code
});

When I execute this code, I get:

.../node_modules/strong-remoting/lib/rest-adapter.js:134
          callback.apply(invocation, args);
                  ^

TypeError: Cannot read property 'apply' of undefined
    at .../node_modules/strong-remoting/lib/rest-adapter.js:134:16
    at execStack (.../node_modules/strong-remoting/lib/remote-objects.js:488:7)
    at RemoteObjects.execHooks (.../node_modules/strong-remoting/lib/remote-objects.js:492:10)
    at HttpInvocation.<anonymous> (.../node_modules/strong-remoting/lib/rest-adapter.js:132:15)
    at HttpInvocation.transformResponse (.../node_modules/strong-remoting/lib/http-invocation.js:337:12)
    at Request._callback (.../node_modules/strong-remoting/lib/http-invocation.js:261:10)
    at Request.self.callback (.../node_modules/request/request.js:199:22)
    at emitTwo (events.js:100:13)
    at Request.emit (events.js:185:7)
    at Request.<anonymous> (.../node_modules/request/request.js:1036:10)

Debugging into rest-adapter, it seems the callback variable is either lost or being cleared somehow. In the following screenshots you can see that callback is still valid until the call to invocation.invoke. When that runs, and its callback is executed, the callback variable has become undefined:

screen shot 2016-03-16 at 3 48 44 pm
screen shot 2016-03-16 at 3 48 58 pm
screen shot 2016-03-16 at 3 49 11 pm

I've tried stepping through the code, but its pretty convoluted so I'm not really sure what is happening.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions