Comparing version 0.0.0 to 0.0.1
@@ -1,4 +0,2 @@ | ||
function abend (error) { | ||
if (error) throw error | ||
} | ||
module.exports = abend | ||
var internal = require('./internal') | ||
module.exports = internal.checkError(internal.createThrower) |
{ | ||
"name": "abend", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"author": "Alan Gutierrez <alan@prettyrobots.com>", | ||
@@ -5,0 +5,0 @@ "description": "Throw an error if there is an error.", |
@@ -5,7 +5,15 @@ # Abend | ||
``` | ||
function abend (error) { | ||
if (error) throw error | ||
if (error) { | ||
setImmediate(function () { throw error }) | ||
} | ||
} | ||
``` | ||
This is an essential function for error-frist callback programming. | ||
The `abend` function will throw an error on the next tick. By throwing the error | ||
outside of the stack that invoked it we can be certain that the error will not | ||
be caught by any `catch` blocks, that it will create an uncaught exception and | ||
terminate the program. |
require('proof')(1, prove) | ||
function prove (assert) { | ||
var abend = require('../..') | ||
try { | ||
abend(new Error('thrown')) | ||
} catch (error) { | ||
assert(error.message, 'thrown', 'caught') | ||
} | ||
try { | ||
abend(null, 1) | ||
} catch (error) { | ||
assert(false, 'should not do anything') | ||
} | ||
assert(require('../..'), 'require') | ||
} |
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
5655
12
31
19