clearbit / clearbit-node

Node library for querying the Clearbit business intelligence APIs
https://clearbit.com/docs
MIT License
69 stars 35 forks source link

this.NotFoundError is not a constructor #32

Closed papandreou closed 6 years ago

papandreou commented 6 years ago

Hi, I've just had this error occur in production (node.js 9.3.0):

TypeError: this.NotFoundError is not a constructor
1
at Function.<anonymous> (/app/node_modules/clearbit/src/resource.js line 25 col 13)
throw new this.NotFoundError(this.name + ' not found');
2
at Function.__NR_wrappedThenHandler (/app/node_modules/newrelic/lib/instrumentation/promise.js line 344 col 23)
return fn.apply(this, arguments)
3
at Function.tryCatcher (/app/node_modules/clearbit/node_modules/bluebird/js/main/util.js line 26 col 23)
return target.apply(this, arguments);
4
at CatchFilter.doFilter (/app/node_modules/clearbit/node_modules/bluebird/js/main/catch_filter.js line 52 col 40)
var ret = tryCatch(cb).call(boundTo, e);
5
at CatchFilter.tryCatcher (/app/node_modules/clearbit/node_modules/bluebird/js/main/util.js line 26 col 23)
return target.apply(this, arguments);
6
at Promise._settlePromiseFromHandler (/app/node_modules/clearbit/node_modules/bluebird/js/main/promise.js line 510 col 31)
x = tryCatch(handler).call(receiver, value);
7
at Promise._settlePromiseAt (/app/node_modules/clearbit/node_modules/bluebird/js/main/promise.js line 584 col 18)
this._settlePromiseFromHandler(handler, receiver, value, promise);
8
at Promise._settlePromises (/app/node_modules/clearbit/node_modules/bluebird/js/main/promise.js line 700 col 14)
this._settlePromiseAt(i);
9
at Async._drainQueue (/app/node_modules/clearbit/node_modules/bluebird/js/main/async.js line 123 col 16)
fn._settlePromises();
10
at Async._drainQueues (/app/node_modules/clearbit/node_modules/bluebird/js/main/async.js line 133 col 10)
this._drainQueue(this._normalQueue);
11
at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/clearbit/node_modules/bluebird/js/main/async.js line 15 col 14)
self._drainQueues();
12
at runCallback (timers.js line 773 col 18)
13
at tryOnImmediate (timers.js line 734 col 5)
14
at processImmediate [as _immediateCallback] (timers.js line 711 col 5)

I've tried and failed to reproduce it in a test setting, but then I stumbled upon https://github.com/petkaantonov/bluebird/issues/973#issuecomment-174216119 -- and it seems like it could be due to some non-Bluebird promise slipping in somewhere, rendering .bind(this) ineffective: https://github.com/clearbit/clearbit-node/blob/c7bf1e04806b3f3343e3b52c942681e63766b841/src/resource.js#L19

Would you accept a patch that avoids the .bind(this) construct? Would be easy to avoid it with arrow functions (node.js 4+) or the good old var that = this; trick if older environments must be supported.

papandreou commented 6 years ago

The plot thickens -- seems like this started happening after we updated https://github.com/newrelic/node-newrelic from 2.5.0 to 2.6.0, where they changed the promise instrumentation.

I've tried fixing it here by switching to arrow functions: https://github.com/clearbit/clearbit-node/pull/33 -- but I'm not able to confirm that it does fix it yet.

papandreou commented 6 years ago

Turns out the problem is in newrelic's end: https://github.com/newrelic/node-newrelic/pull/260#issuecomment-369089224

Closing this issue :)