Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added example to show weird errors and then fixed it.

  • Loading branch information...
commit d3b854cecf8a9277081518b3c5c7d12fa7eee559 1 parent 28c0399
@dominictarr dominictarr authored
Showing with 22 additions and 3 deletions.
  1. +2 −3 lib/child.js
  2. +7 −0 lib/testing.js
  3. +13 −0 test/test-weird_throws.js
View
5 lib/child.js
@@ -28,9 +28,8 @@ function postMessage() {
function makeErrorJsonable(err) {
var r = new RegExp(process.cwd(),'g')
-
return {
- message: err.message ? err.message : null
- , stack: err.stack.replace(r, '.')
+ message: err.message || null
+ , stack: err.stack ? err.stack.replace(r, '.') : '[no stack trace]'
}
}
View
7 lib/testing.js
@@ -2,6 +2,7 @@ var assert = require('assert')
, path = require('path')
, fs = require('fs')
, spawn = require('child_process').spawn
+ , inspect = require('util').inspect
;
/* Runs an object with tests. Each property in the object should be a
@@ -233,6 +234,12 @@ exports.runSuite = function(obj, options) {
return testProgressed(t, err);
}
+ // if the error is not an instance of Error (& has no stack trace) wrap in proper error
+
+// console.log(inspect(err))
+ if('object' !== typeof err)
+ err = new Error (typeof err + " thrown:" + inspect(err) + " (intercepted by async_testing)")
+
// We want to allow tests to supply a function for handling uncaught errors,
// and since all uncaught errors come here, this is where we have to handle
// them.
View
13 test/test-weird_throws.js
@@ -18,4 +18,17 @@ module.exports = {
, 'test throw String': function(test) {
throw 'hello';
}
+/*, 'test throw error without stack': function(test) {
+ //weird but it happens some times... stackoverflow, for example.
+ var e = new Error ("THIS ERROR HAS NO STACK TRACE")
+ delete e.stack
+ throw e
+ }*/
+, 'test stack overflow': function(test) {
+ //weird but it happens some times... stackoverflow, for example.
+ function overflow(){
+ overflow()
+ }
+ overflow()
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.