Comparing version 0.2.1 to 0.2.2
33
index.js
@@ -22,2 +22,3 @@ 'use strict'; | ||
callback({ | ||
// culprit: | ||
properties: getProperties(err), | ||
@@ -34,2 +35,3 @@ frames: stack | ||
callsite.getRelativeFileName = getRelativeFileName.bind(callsite); | ||
callsite.getTypeNameSafely = getTypeNameSafely.bind(callsite); | ||
callsite.getFunctionNameSanitized = getFunctionNameSanitized.bind(callsite); | ||
@@ -88,6 +90,5 @@ callsite.getModuleName = getModuleName.bind(callsite); | ||
var getFunctionNameSanitized = function () { | ||
var getTypeNameSafely = function () { | ||
try { | ||
return this.getFunctionName() || | ||
this.getTypeName() + '.' + (this.getMethodName() || '<anonymous>'); | ||
return this.getTypeName(); | ||
} catch (e) { | ||
@@ -97,6 +98,30 @@ // This seems to happen sometimes when using 'use strict', | ||
// [TypeError: Cannot read property 'constructor' of undefined] | ||
return '<anonymous>'; | ||
return null; | ||
} | ||
}; | ||
var getFunctionNameSanitized = function () { | ||
var fnName = this.getFunctionName(); | ||
if (fnName) return fnName; | ||
var typeName = this.getTypeNameSafely(); | ||
if (typeName) return typeName + '.' + (this.getMethodName() || '<anonymous>'); | ||
return '<anonymous>'; | ||
}; | ||
var getCulprit = function () { | ||
// module | ||
// file | ||
// function/object/method | ||
// | ||
// ModuleName: file.function | ||
// ModuleName: Type.method | ||
var filename; | ||
if (this.isNode()) { | ||
filename = this.getFileName(); | ||
} else { | ||
} | ||
var module = this.getModuleName(); | ||
}; | ||
var getModuleName = function () { | ||
@@ -103,0 +128,0 @@ var filename = this.getFileName() || ''; |
{ | ||
"name": "stackman", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Enhance an error stacktrace with code excerpts and other goodies", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -77,2 +77,3 @@ # Stackman | ||
- `callsite.getTypeNameSafely()` - A safer version of `callsite.getTypeName()` as this safely handles an exception that sometimes is thrown when using `"use strict"`. Otherwise it returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property | ||
- `callsite.getRelativeFileName()` - Returns a filename realtive to `process.cwd()` | ||
@@ -79,0 +80,0 @@ - `callsite.getFunctionNameSanitized()` - Guaranteed to always return the most meaningful function name. If none can be determined, the string `<anonymous>` will be returned |
12
test.js
@@ -8,2 +8,14 @@ 'use strict'; | ||
test('should override getTypeName() and safely catch exception', function (t) { | ||
process.nextTick(function () { | ||
var err = new Error('foo'); | ||
stackman()(err, function (stack) { | ||
var frame =stack.frames[0]; | ||
var name = frame.getFunctionNameSanitized(); | ||
t.equal(name, '<anonymous>', 'should safely catch exception'); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
test('should call the callback with a stack object', function (t) { | ||
@@ -10,0 +22,0 @@ var err = new Error(); |
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
14548
8
228
107