Comparing version 0.0.1 to 0.0.2
var internal = require('./internal') | ||
module.exports = internal.checkError(internal.createThrower) | ||
module.exports = internal.checkError(internal.createThrower, process.stderr) |
@@ -1,5 +0,6 @@ | ||
exports.checkError = function (createHandler) { | ||
exports.checkError = function (createHandler, stderr) { | ||
return function (error) { | ||
if (error) { | ||
setImmediate(createHandler(error)) | ||
setImmediate(createHandler(error, stderr)) | ||
throw error | ||
} | ||
@@ -9,4 +10,7 @@ } | ||
exports.createThrower = function (error) { | ||
return function () { throw error } | ||
exports.createThrower = function (error, stderr) { | ||
return function () { | ||
stderr.write('WARNING: rethrowning caught error\n') | ||
throw error | ||
} | ||
} |
{ | ||
"name": "abend", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Alan Gutierrez <alan@prettyrobots.com>", | ||
@@ -26,3 +26,3 @@ "description": "Throw an error if there is an error.", | ||
{ | ||
"proof": "0.0.52" | ||
"proof": "0.0.56" | ||
}, | ||
@@ -29,0 +29,0 @@ "scripts": |
@@ -1,9 +0,12 @@ | ||
require('proof')(2, prove) | ||
require('proof')(3, prove) | ||
function prove (assert, callback) { | ||
var internal = require('../../internal') | ||
var stream = require('stream') | ||
var stderr = new stream.PassThrough | ||
try { | ||
internal.createThrower(new Error('thrown'))() | ||
internal.createThrower(new Error('thrown'), stderr)() | ||
} catch (error) { | ||
assert(stderr.read().toString(), 'WARNING: rethrowning caught error\n', 'stderr') | ||
assert(error.message, 'thrown', 'thrower') | ||
@@ -13,8 +16,14 @@ } | ||
var handler = internal.checkError(function (error) { | ||
assert(error.message, 'given', 'abended') | ||
callback() | ||
}) | ||
return function () { | ||
assert(error.message, 'given', 'abended') | ||
callback() | ||
} | ||
}, stderr) | ||
handler() | ||
handler(new Error('given')) | ||
try { | ||
handler(new Error('given')) | ||
} catch (error) { | ||
// swallow error to test hedge. | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6114
44