Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trycatch

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trycatch - npm Package Compare versions

Comparing version 1.5.8 to 1.5.9

18

lib/formatError.js

@@ -16,3 +16,3 @@ var path = require('path')

function formatError(err, stack, options) {
normalizeError(err, stack)
if (!err.normalized) normalizeError(err, stack)

@@ -35,3 +35,2 @@ stack = formatStack(stack || ''

}
err.stack
return err

@@ -42,6 +41,10 @@ }

function normalizeError(err, stack) {
addNonEnumerableValue(err, 'originalStack', stack || err.message)
addNonEnumerableValue(err, 'normalized', true)
addNonEnumerableValue(err, 'coreThrown', isCoreError(err))
addNonEnumerableValue(err, 'catchable', isCatchableError(err))
err = coerceToError(err)
if (!err.normalized) {
addNonEnumerableValue(err, 'originalStack', stack || err.message)
addNonEnumerableValue(err, 'normalized', true)
addNonEnumerableValue(err, 'coreThrown', isCoreError(err))
addNonEnumerableValue(err, 'catchable', isCatchableError(err))
}
return err
}

@@ -140,2 +143,3 @@

module.exports.coerceToError = coerceToError
module.exports.addNonEnumerableValue = addNonEnumerableValue
module.exports.normalizeError = normalizeError
module.exports.addNonEnumerableValue = addNonEnumerableValue

@@ -8,3 +8,3 @@ var domain = require('domain')

, formatStackWithOptions = formatErrorModule.formatStack
, coerceToError = formatErrorModule.coerceToError
, normalizeError = formatErrorModule.normalizeError
, addNonEnumerableValue = formatErrorModule.addNonEnumerableValue

@@ -57,3 +57,5 @@ , delimitter = '\n ----------------------------------------\n'

d.on('error', _trycatchOnError)
trycatch.sameTick = true
runInDomain(d, tryFn, trycatchit)
trycatch.sameTick = false

@@ -67,4 +69,4 @@ if (isLST) {

function _trycatchOnError(err) {
err = coerceToError(err)
if (!err.normalized) err.stack = formatError(err, err.stack)
err = normalizeError(err)
if (Error.stackTraceLimit === 0) err.stack = err.originalStack

@@ -82,7 +84,5 @@ if (!err.catchable) {

if (isLST) {
if (err.rethrown) {
if (err.parentStack) {
err.stack += delimitter + err.parentStack
err.parentStack = undefined
}
if (err.rethrown && err.parentStack) {
err.stack += delimitter + err.parentStack
err.parentStack = undefined
}

@@ -103,2 +103,18 @@

function Stack(unformattedStack, parentStack) {
this.unformattedStack = unformattedStack
this.parentStack = parentStack
}
Stack.prototype.toString = function() {
// Format frames and chop off leading non-stack portion
if (this.stack === undefined) {
// When stackTraceLimit === 0, stack is empty
this.stack = formatStack(this.unformattedStack.substr(16))
this.unformattedStack = undefined
this.parentStack = this.parentStack ? delimitter + this.parentStack : ''
}
return this.stack + this.parentStack
}
// Generate a new callback

@@ -120,8 +136,9 @@ // Ensure it runs in the same domain

// Inherit from callback for when properties are added
newCallback.__proto__ = callback
return newCallback
_trycatchNewCallback.__proto__ = callback
_trycatchNewCallback._trycatchCurrentStack = stack
return _trycatchNewCallback
function newCallback() {
function _trycatchNewCallback() {
// Don't stomp stack in synchronous EventEmitter case
if (isLST) trycatch.currentStack = stack
runInDomain(d, callback, trycatchit, this, arguments)

@@ -132,15 +149,5 @@ }

function getUpdatedCurrentStack() {
var stack = ''
if (!options['long-stack-traces']) return
// Get new stack and chop off leading non-stack portion
// MUST use Error.captureStackTrace to avoid stack filtering
Error.captureStackTrace(stackHolder)
stack = stackHolder.stack
if (trycatch.currentStack) {
stack += delimitter + trycatch.currentStack
}
return stack
return stackHolder.stack ? new Stack(stackHolder.stack, trycatch.currentStack) : ''
}

@@ -156,3 +163,3 @@

if (err) {
err = coerceToError(err)
err = normalizeError(err)
if (hasDomain) {

@@ -314,11 +321,18 @@ d.emit('error', err)

var stack = FormatStackTrace.call(this, err, frames)
if (err === stackHolder) {
// When stackTraceLimit === 0, stack is empty
stack = stack && stack.substr(16)
return formatStack(stack)
}
, i, l
if (err === stackHolder) return stack
stack = formatError(err, stack)
if (options['long-stack-traces'] && trycatch.currentStack) {
stack += delimitter + trycatch.currentStack
if (options['long-stack-traces']) {
if (!trycatch.sameTick) {
for (i=0, l=frames.length; i<l; i++) {
if ('_trycatchNewCallback' === frames[i].getFunctionName()) {
stack += delimitter + frames[i].getFunction()._trycatchCurrentStack
break
}
}
} else if (trycatch.currentStack) {
stack += delimitter + trycatch.currentStack
}
}

@@ -325,0 +339,0 @@ return stack

{
"name": "trycatch",
"version": "1.5.8",
"version": "1.5.9",
"description": "An asynchronous domain-based exception handler with long stack traces for node.js",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/CrabDude/trycatch",

var trycatch = require('../lib/trycatch')
, assert = require('assert')
, delimitter = '----------------------------------------'

@@ -72,2 +73,20 @@

})
it('should generate correct stack when err.stack lazily accessed', function(done) {
var err
trycatch(function() {
setTimeout(function() {
err = new Error()
process.nextTick(function() {
assert(err.stack.split('\n')[2].indexOf('timeout') !== -1)
assert.equal(err.stack.split(delimitter).length, longStackTraces ? 2 : 1)
done()
})
})
}
, function(err) {
throw err
})
})
})

@@ -74,0 +93,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