TritonDataCenter / node-verror

Rich JavaScript errors
MIT License
1.18k stars 61 forks source link

Property 'captureStackTrace' is not a function #18

Closed TheLudd closed 8 years ago

TheLudd commented 9 years ago

Hello. I am not a direct user of verror, only indirect via restify, and I have this problem:

When running tests against my rest api and an assertion-error is thrown the entire test runner breaks down because of this error:

/home/ludwig/myproject/node_modules/restify/node_modules/verror/lib/verror.js:147
    Error.captureStackTrace(this, ctor || this.constructor);
          ^
TypeError: Property 'captureStackTrace' of object function Error() { [native code] } is not a function
  at [object Object].WError (/home/ludwig/myproject/node_modules/restify/node_modules/verror/lib/verror.js:147:8)
  at [object Object].HttpError (/home/ludwig/myproject/node_modules/restify/lib/errors/http_error.js:44:12)
  at [object Object].RestError (/home/ludwig/myproject/node_modules/restify/lib/errors/rest_error.js:41:15)
  at new module.exports.(anonymous function) (/home/ludwig/myproject/node_modules/restify/lib/errors/rest_error.js:86:19)
  at Server.<anonymous> (/home/ludwig/myproject/node_modules/restify/lib/index.js:111:18)
  at Server.emit (events.js:106:17)
  at Domain.onError (/home/ludwig/myproject/node_modules/restify/lib/server.js:775:18)
  at Domain.emit (events.js:95:17)
  at Async$_consumeLateBuffer [as _consumeLateBuffer] (/home/ludwig/myproject/node_modules/bluebird/js/main/async.js:93:27)
  at Async$_consumeFunctionBuffer [as _consumeFunctionBuffer] (/home/ludwig/myproject/node_modules/bluebird/js/main/async.js:80:10)
  at Async$consumeFunctionBuffer (/home/ludwig/myproject/node_modules/bluebird/js/main/async.js:40:14)
  at process._tickDomainCallback (node.js:463:13)

I really don't understand much of this but I notice that in some parts of the verror code there is a check: ìf (Error.captureStackTrace) before using that function. This does not exist at the specific line (147) but if I add a check at that point my problem disappears and the assertion error message is correctly printed.

Is this a check that can be added to the code to solve my problem?

davepacheco commented 9 years ago

I had not seen this problem before. What version of Node is this, and on what platform?

TheLudd commented 9 years ago

Ubuntu 14.04, Node 0.10.33

davepacheco commented 9 years ago

If you start up a Node REPL and run this, what do you get:

$ node
> Error.captureStackTrace
[Function: captureStackTrace]
TheLudd commented 9 years ago

Same as you

davepacheco commented 8 years ago

This should be fixed by my refactoring for #10, but I'm still not sure why Error.captureStackTrace isn't present when this happens. Do you understand why that's happening?

TheLudd commented 8 years ago

Sorry, this was a long time ago. I can't really remember the issue and I haven't run across it since we last spoke.

davepacheco commented 8 years ago

Closing as a dup of #10, which should have fixed this.