Comparing version 0.0.1 to 0.1.0
@@ -0,3 +1,12 @@ | ||
0.1.0 / 2013-02-18 | ||
------------------ | ||
* Fixed bugs due to setting of `uncaughtException`. | ||
* Changed default of `uncaughtException` from `true` to `false`. | ||
* Removed aliases for `uncaughtException`. | ||
* Fixed bug that when a key is set to false, it's still caught. | ||
* Passed signal to callback. | ||
0.0.1 / 2012-12-01 | ||
------------------ | ||
* Initial release. |
var defaultConfig = { | ||
uncaughtException: true, | ||
uncaughtException: false, | ||
SIGINT: true, | ||
@@ -13,9 +13,18 @@ SIGTERM: true, | ||
Object.keys(defaultConfig).forEach(function(key) { | ||
if (DEBUG) | ||
process.on(key, function() { | ||
console.log('Trapped ' + key) | ||
callback.apply(null, arguments) | ||
}) | ||
else | ||
process.on(key, callback) | ||
var val = defaultConfig[key] | ||
if (val) { | ||
if (DEBUG) | ||
process.on(key, function() { | ||
var args = Array.prototype.slice.call(arguments, 0) | ||
args.unshift(key) | ||
console.log('Trapped ' + key) | ||
callback.apply(null, args) | ||
}) | ||
else | ||
process.on(key, function() { | ||
var args = Array.prototype.slice.call(arguments, 0) | ||
args.unshift(key) | ||
callback.apply(null, args) | ||
}) | ||
} | ||
}) | ||
@@ -26,8 +35,8 @@ } | ||
if (typeof arg === 'object') { | ||
DEBUG = arg.debug || arg.DEBUG | ||
if (arg['debug']) | ||
DEBUG = arg.debug | ||
if (arg['DEBUG']) | ||
DEBUG = arg.DEBUG | ||
delete arg.debug; delete arg.DEBUG; | ||
defaultConfig.uncaughtException = arg.ue || arg.uncaught || arg.exception || true | ||
delete arg.ue; delete arg.uncaught; delete arg.exception | ||
Object.keys(arg).forEach(function(key) { | ||
@@ -34,0 +43,0 @@ defaultConfig[key] = arg[key] |
{ | ||
"name" : "death", | ||
"version" : "0.0.1", | ||
"description" :"Gracefully cleanup when termination signals are sent to your process.", | ||
"homepage" : [ | ||
"" | ||
], | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "git@github.com:jprichardson/node-death.git" | ||
}, | ||
"keywords" : ["sigint", "sigterm", "sigkill", "sigquit", "exception", "kill", "terminate", "process", "clean"], | ||
"author" : "JP Richardson <jprichardson@gmail.com>", | ||
"licenses" : [ { | ||
"type" : "MIT", | ||
"url" : "" | ||
}], | ||
"dependencies" : {}, | ||
"devDependencies":{}, | ||
"main" : "./lib/death.js", | ||
"scripts": { | ||
"test": "mocha test" | ||
"name": "death", | ||
"version": "0.1.0", | ||
"description": "Gracefully cleanup when termination signals are sent to your process.", | ||
"homepage": [ | ||
"" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:jprichardson/node-death.git" | ||
}, | ||
"keywords": [ | ||
"sigint", | ||
"sigterm", | ||
"sigkill", | ||
"sigquit", | ||
"exception", | ||
"kill", | ||
"terminate", | ||
"process", | ||
"clean" | ||
], | ||
"author": "JP Richardson <jprichardson@gmail.com>", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "" | ||
} | ||
], | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"win-spawn": "~1.1.1", | ||
"autoresolve": "0.0.3", | ||
"testutil": "~0.4.0", | ||
"colors": "~0.6.0-1" | ||
}, | ||
"main": "./lib/death.js", | ||
"scripts": { | ||
"test": "mocha test" | ||
} | ||
} |
Node.js - death | ||
================ | ||
Conveniently cleanup when termination signals are sent to your process. | ||
Gracefully cleanup when termination signals are sent to your process. | ||
@@ -51,8 +51,11 @@ | ||
#### Don't want to catch uncaughtException? | ||
AS they pertain to Node.js: http://dailyjs.com/2012/03/15/unix-node-signals/ | ||
#### Want to catch uncaughtException? | ||
No problem, do this: | ||
```js | ||
var ON_DEATH = require('death')({uncaughtException: false}) //could also use alias: 'uncaught', 'ue', or 'exception'. | ||
var ON_DEATH = require('death')({uncaughtException: true}) | ||
``` | ||
@@ -59,0 +62,0 @@ |
@@ -1,2 +0,163 @@ | ||
var exec = require('child_process').exec | ||
var spawn = require('win-spawn') | ||
, P = require('autoresolve') | ||
, testutil = require('testutil') | ||
, colors = require('colors') | ||
describe('death', function() { | ||
describe('default behavior', function() { | ||
it('should catch SIGINT, SIGTERM, and SIGQUIT and return 3', function(done) { | ||
var signals = [] | ||
var progPath = P('test/resources/default') | ||
var prog = spawn(progPath, []) | ||
//console.dir(prog) | ||
prog.stdout.on('data', function(data) { | ||
//console.log(colors.cyan(data.toString())) | ||
}) | ||
prog.stderr.on('data', function(data) { | ||
//console.error(colors.red(data.toString())) | ||
signals = signals.concat(data.toString().trim().split('\n')) | ||
}) | ||
prog.on('exit', function(code) { | ||
EQ (code, 3) | ||
//console.dir(signals) | ||
T (signals.indexOf('SIGQUIT') >= 0) | ||
T (signals.indexOf('SIGTERM') >= 0) | ||
T (signals.indexOf('SIGINT') >= 0) | ||
done() | ||
}) | ||
setTimeout(function() { | ||
prog.kill('SIGINT') | ||
process.kill(prog.pid, 'SIGTERM') | ||
prog.kill('SIGQUIT') | ||
}, 100) | ||
}) | ||
}) | ||
describe('other signal', function() { | ||
it('should catch SIGINT, SIGTERM, SIGQUIT, and SIGHUP and return 4', function(done) { | ||
var signals = [] | ||
var progPath = P('test/resources/sighup') | ||
var prog = spawn(progPath, []) | ||
//console.dir(prog) | ||
prog.stdout.on('data', function(data) { | ||
//console.log(colors.cyan(data.toString())) | ||
}) | ||
prog.stderr.on('data', function(data) { | ||
//console.error(colors.red(data.toString())) | ||
signals = signals.concat(data.toString().trim().split('\n')) | ||
}) | ||
prog.on('exit', function(code) { | ||
EQ (code, 4) | ||
//console.dir(signals) | ||
T (signals.indexOf('SIGQUIT') >= 0) | ||
T (signals.indexOf('SIGTERM') >= 0) | ||
T (signals.indexOf('SIGINT') >= 0) | ||
T (signals.indexOf('SIGHUP') >= 0) | ||
done() | ||
}) | ||
setTimeout(function() { | ||
prog.kill('SIGINT') | ||
process.kill(prog.pid, 'SIGTERM') | ||
prog.kill('SIGQUIT') | ||
prog.kill('SIGHUP') | ||
}, 100) | ||
}) | ||
}) | ||
describe('disable signal', function() { | ||
it('should catch SIGINT and SIGTERM', function(done) { | ||
var signals = [] | ||
var progPath = P('test/resources/disable') | ||
var prog = spawn(progPath, []) | ||
//console.dir(prog) | ||
prog.stdout.on('data', function(data) { | ||
//console.log(colors.cyan(data.toString())) | ||
}) | ||
prog.stderr.on('data', function(data) { | ||
//console.error(colors.red(data.toString())) | ||
signals = signals.concat(data.toString().trim().split('\n')) | ||
}) | ||
prog.on('exit', function(code) { | ||
T (signals.indexOf('SIGQUIT') < 0) | ||
T (signals.indexOf('SIGTERM') >= 0) | ||
T (signals.indexOf('SIGINT') >= 0) | ||
done() | ||
}) | ||
setTimeout(function() { | ||
prog.kill('SIGINT') | ||
prog.kill('SIGTERM') | ||
setTimeout(function() { | ||
prog.kill('SIGQUIT') //this actually kills it since we disabled it | ||
},10) | ||
}, 100) | ||
}) | ||
}) | ||
describe('uncaughException', function() { | ||
describe('> when set to true', function() { | ||
it('should catch uncaughtException', function(done) { | ||
var errData = '' | ||
var progPath = P('test/resources/uncaughtException-true') | ||
var prog = spawn(progPath, []) | ||
//console.dir(prog) | ||
prog.stdout.on('data', function(data) { | ||
//console.log(colors.cyan(data.toString())) | ||
}) | ||
prog.stderr.on('data', function(data) { | ||
//console.error(colors.red(data.toString())) | ||
errData += data.toString().trim() | ||
}) | ||
prog.on('exit', function(code) { | ||
EQ (code, 70) | ||
T (errData.indexOf('uncaughtException') >= 0) | ||
T (errData.indexOf('UNCAUGHT SELF') >= 0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
describe('> when set to false', function() { | ||
it('should catch uncaughtException', function(done) { | ||
var errData = '' | ||
var progPath = P('test/resources/uncaughtException-false') | ||
var prog = spawn(progPath, []) | ||
//console.dir(prog) | ||
prog.stdout.on('data', function(data) { | ||
//console.log(colors.cyan(data.toString())) | ||
}) | ||
prog.stderr.on('data', function(data) { | ||
//console.error(colors.red(data.toString())) | ||
errData += data.toString().trim() | ||
}) | ||
prog.on('exit', function(code) { | ||
EQ (code, 1) | ||
T (errData.indexOf('CAUGHT: uncaughtException') < 0) | ||
T (errData.indexOf('UNCAUGHT SELF') >= 0) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
12078
14
192
97
4