'Request does something that throws an error' : {
topic: function () {
var req = require('http').request({
hostname : 'www.google.com',
port : 80,
path : '/',
method : 'GET'
}, function(res) {
throw new Error('error!') // Error should be caught
})
req.end()
},
'Must reach here': function () {
assert.ok(true); // Reach here at the end of test
},
},
I should see something like this:
Request does something that throws an error
✓ Must reach here
Instead this happens:
/Users/lxe/devel/vows_test/test_request:115
throw new Error('error!') // Error should be caught
^
Error: error!
at ClientRequest.<anonymous> (/Users/lxe/devel/vows_test/test_request.js:115:23)
at ClientRequest.g (events.js:192:14)
at ClientRequest.EventEmitter.emit (events.js:96:17)
at ClientRequest.vows.describe.options.Emitter.emit (/Users/lxe/devel/vows_test/node_modules/vows/lib/vows.js:237:24)
at HTTPParser.parserOnIncomingClient [as onIncoming] (http.js:1462:7)
at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
at Socket.socketOnData [as ondata] (http.js:1367:20)
at TCP.onread (net.js:404:27)
When I'm running a regular asynchronous function that throws an error, everything is OK:
'Regular async function does something that throws an error' : {
topic: function () {
(function(callback) {
callback()
})(function() {
throw new Error('error!') // Error should be caught
})
},
'Must reach here': function () {
assert.ok(true); // Reach here at the end of test
},
},
Regular async function does something that throws an error
✓ Must reach here
Here's the code I'm running to test this:
I should see something like this:
Instead this happens:
When I'm running a regular asynchronous function that throws an error, everything is OK:
Originally I was using https://github.com/mikeal/request and discovered this, but I since narrowed it down to
http.request()
call.I'm using vows 0.7.0.