New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

laeh2

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laeh2 - npm Package Compare versions

Comparing version 0.2.8 to 0.3.0

200

lib/laeh2.js

@@ -32,7 +32,7 @@

var _capturePrevious = true;
var _capturePrevious = !(process.env.NODE_ENV === 'production');
exports.capturePrevious = function(bool) {
_capturePrevious = bool;
return exports;
_capturePrevious = bool;
return exports;
};

@@ -48,12 +48,12 @@

var o = e instanceof Object;
var a = Array.isArray(e);
var o = e instanceof Object;
var a = Array.isArray(e);
if(o || a) {
for(var k in (o ? Object.keys(e) : e))
if(e[k] instanceof Error)
e[k] = String(e[k].stack);
}
return JSON.stringify(e);
if(o || a) {
for(var k in (o ? Object.keys(e) : e))
if(e[k] instanceof Error)
e[k] = String(e[k].stack);
}
return JSON.stringify(e);
}

@@ -66,10 +66,10 @@

exports._e = _e = function(e, meta) {
if(e) {
if(!(e instanceof Error))
e = new Error(e instanceof Object ? exports.laehStringify(e) : e);
if(meta)
e.meta = meta;
throw e;
}
exports._e = function(e, meta) {
if(e) {
if(!(e instanceof Error))
e = new Error(e instanceof Object ? exports.laehStringify(e) : e);
if(meta)
e.meta = meta;
throw e;
}
};

@@ -83,47 +83,51 @@

exports._x = _x = function(cb, chk, func) {
exports._x = function(cb, chk, func) {
if(cb && typeof(cb) !== 'function')
throw new Error('cb is not a function');
if(cb && typeof(cb) !== 'function')
throw new Error('cb is not a function');
if(typeof(func) !== 'function')
throw new Error('func is not a function');
var prev = _capturePrevious ? new Error(/*'previous thread'*/) : null;
// the 'arg' below is there to support laeh's use in Mocha, as:
// it('my test', _x(null, false, function(done) { ... done(); }));
return function(arg) {
try {
if(chk)
_e(arguments[0]);
func.apply(null, arguments);
}
catch(e) {
var lcb = cb;
if(typeof(func) !== 'function')
throw new Error('func is not a function');
var prev = _capturePrevious ? new Error(/*'previous thread'*/).stack : null;
// the 'arg' below is there to support laeh's use in Mocha, as:
// it('my test', _x(null, false, function(done) { ... done(); }));
var ret = function(arg) {
try {
if(chk)
exports._e(arguments[0]);
func.apply(null, arguments);
}
catch(e) {
var lcb = cb;
if(!lcb)
lcb = arguments.length > 0 && typeof(arguments[arguments.length-1]) === 'function' ?
arguments[arguments.length-1] : null;
if(!lcb)
lcb = arguments.length > 0 && typeof(arguments[arguments.length-1]) === 'function' ?
arguments[arguments.length-1] : null;
if(!(e instanceof Error))
e = new Error(e instanceof Object ? exports.laehStringify(e) : e);
e.prev = prev;
if(!lcb) {
// programmer error, OK to exit Node
// would result in unclean state if silently
// handled in the uncaught handler
var e2 = new Error('laeh2: missing callback');
e2.prev = e;
throw e2;
}
lcb(e);
}
};
if(!(e instanceof Error))
e = new Error(e instanceof Object ? exports.laehStringify(e) : e);
e.prev = /*this.*/prev;
if(!lcb) {
// programmer error, OK to exit Node
// would result in unclean state if silently
// handled in the uncaught handler
var e2 = new Error('laeh2: missing callback');
e2.prev = e;
throw e2;
}
lcb(e);
}
};
return ret;
//})(cb, chk, func);
};

@@ -140,40 +144,40 @@

Error.prepareStackTrace = function(e, s) {
var stack = [];
var cwd = new RegExp(process.cwd().replace(/[.^|$*?\[\]\\{}:!\/+()]/g, '\\$&'));
var prev;
var fs = frameSeparator || ' < ';
for(var i = 0; i < s.length; i++) {
var f = s[i];
var n = (f.getFileName() || '?').replace(cwd, '.').replace(/node_modules/g, '$');
var c = n.charAt(0);
if(hiding && ((c !== '.' && c !== '/') || /.*?laeh2.js$/.exec(n)))
continue;
var ln = (f.getLineNumber() || '?') + (f.isEval() ? '*' : '') + (f.isNative() ? '+' : '');
if(prev == n)
stack[stack.length - 1] += ' < ' + ln;
else
stack.push(n + '(' + ln);
prev = n;
}
for(var i = 0; i < stack.length; i++)
stack[i] += ')'
var msg = '';
if(e.message)
msg += e.message + fs;
if(e.meta)
msg += (typeof(e.meta) === 'object' ?
JSON.stringify(e.meta, null, prettyMeta) : String(e.meta)) + ' ';
msg += stack.join(fs);
if(e.prev)
msg += (fiberSeparator || ' << ') + e.prev.stack;
return msg;
};
Error.prepareStackTrace = function(e, s) {
var stack = [];
var cwd = new RegExp(process.cwd().replace(/[.^|$*?\[\]\\{}:!\/+()]/g, '\\$&'));
var prev;
var fs = frameSeparator || ' < ';
for(var i = 0; i < s.length; i++) {
var f = s[i];
var n = (f.getFileName() || '?').replace(cwd, '.').replace(/node_modules/g, '$');
var c = n.charAt(0);
if(hiding && ((c !== '.' && c !== '/') || /.*?laeh2.js$/.exec(n)))
continue;
var ln = (f.getLineNumber() || '?') + (f.isEval() ? '*' : '') + (f.isNative() ? '+' : '');
if(prev == n)
stack[stack.length - 1] += ' < ' + ln;
else
stack.push(n + '(' + ln);
prev = n;
}
for(var i = 0; i < stack.length; i++)
stack[i] += ')'
var msg = '';
if(e.message)
msg += e.message + fs;
if(e.meta)
msg += (typeof(e.meta) === 'object' ?
JSON.stringify(e.meta, null, prettyMeta) : String(e.meta)) + ' ';
msg += stack.join(fs);
if(e.prev)
msg += (fiberSeparator || ' << ') + (e.prev.stack || e.prev);
return msg;
};
return exports;
return exports;
};
{
"author": "Juraj Vitko (ypocat.com)",
"name": "laeh2",
"description": "Lightweight Asynchronous Error Handling v2",
"keywords": [ "error", "handling", "asynchronous" ],
"version": "0.2.8",
"homepage": "http://github.com/ypocat/laeh2",
"repository": {
"type": "git",
"url": "git://github.com/ypocat/laeh2.git"
},
"main": "./lib/laeh2.js",
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">= 0.4.0"
},
"dependencies": {
},
"devDependencies": {
},
"licenses": [
{ "type" : "MIT", "url" : "https://raw.github.com/ypocat/laeh2/master/LICENSE" }
]
"author": "Juraj Vitko (ypocat.com)",
"name": "laeh2",
"description": "Lightweight Asynchronous Error Handling v2",
"keywords": [ "error", "handling", "asynchronous" ],
"version": "0.3.0",
"homepage": "http://github.com/ypocat/laeh2",
"repository": {
"type": "git",
"url": "git://github.com/ypocat/laeh2.git"
},
"main": "./lib/laeh2.js",
"directories": {
"lib": "./lib"
},
"engines": {
"node": ">= 0.4.0"
},
"dependencies": {
},
"devDependencies": {
},
"licenses": [
{ "type" : "MIT", "url" : "https://raw.github.com/ypocat/laeh2/master/LICENSE" }
]
}
# Lightweight Asynchronous Error Handling v2 for Node.js (LAEH2)
## Important Changes for >= 0.3.0
### Change 1
The `_x()` and `_e()` functions are no longer placed to the global space, and you need to explicitly declare them in your module as `var _x = laeh2._x;` and `var _e = laeh2._e;` (that is, if you need to use `_e` at all).
The reason for this is that in some situations, Node/V8 had trouble to garbage-collect data created in functions wrapped by the `_x()` function, although this works perfectly fine when you reassign the `_x` function locally in your module.
This change breaks existing code, but it's very easy to fix. Bug report for Node/V8 for this issue wasn't filled yet.
### Change 2
The `capturePrevious` flag now defaults to the opposite of `process.env.NODE_ENV === 'production'`, which means that if you want to have asynchronous stack-traces captured in production, you need to use `.capturePrevious(true)` explicitly.
Another change here is that when `capturePrevious` is `true`, the stack-traces are no longer stored inside Error instances, but serialized during the capturing phase. This solves another mysterious garbage-collecting problem, similar to the one described above. This also adds a tiny extra overhead to the capturing phase.
## Evolution

@@ -56,5 +73,3 @@

Note: the _x and the _e functions are globals.
### 4. Optional Goodies

@@ -78,3 +93,3 @@

var laeh = require('laeh2').leanStacks(true);
var _e = laeh._e; // optional
var _e = laeh._e;
var _x = laeh._x;

@@ -81,0 +96,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc