Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runner.prototype.uncaught should not assume err object exists #1072

Closed
jcollum-hcg opened this issue Dec 15, 2013 · 4 comments
Closed

Runner.prototype.uncaught should not assume err object exists #1072

jcollum-hcg opened this issue Dec 15, 2013 · 4 comments

Comments

@jcollum-hcg
Copy link

I can submit a PR for this, but I'd like to confirm that I have the issue correct before I do.

Runner.prototype.uncaught = function(err){
  debug('uncaught exception %s', err.message);

Problem is that err is undefined.

Changing to this:

Runner.prototype.uncaught = function(err){

  if (typeof err === "undefined" || err === null) {
    err = {};
    err.message = "(no message found)";
  } 
  debug('uncaught exception %s', err.message);

fixes it well enough, but I wonder if mocha is expecting node to throw an error of a certain shape and that's no longer the case.

$ mocha --version
1.15.1

$ which mocha
/home/dev/.nvm/v0.10.23/bin/mocha

$ which node
/home/dev/.nvm/v0.10.23/bin/node

@witoldsz
Copy link

+1
I had a problem with this when my library was throwing an exception which was an object with no message property. The test failed, but it did not provide ANY information about what happened. Not a single word about an exception, no nothing.

@jcollum-hcg
Copy link
Author

Wow I had forgotten about this issue until you commented. 3 months and none of the devs have touched it -- even after I offered to help fix it? Hrm.

@tj
Copy link
Contributor

tj commented Mar 18, 2014

err || {} would do

@rlidwka
Copy link

rlidwka commented Mar 29, 2014

err || {} would do

It would fail on other primitives, and certainly not solves @witoldsz 's issue.

Full solution could be like this:

( err !== function() { return this }.call(err) ) ? err : ( err.message || err )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants