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

stackman

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stackman - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

test/fixtures/lib/error-broken.js

17

index.js

@@ -53,3 +53,5 @@ 'use strict'

sourcemapify(_callsites, function (err) {
if (err) return cb(err)
if (err) {
debug('error processing source map: %s', err.message)
}
_callsites.forEach(extendCallsite)

@@ -294,6 +296,11 @@ cb(null, _callsites)

if (!position) {
position = callsite.sourcemap.originalPositionFor({
line: getLineNumber.call(callsite),
column: getColumnNumber.call(callsite)
})
try {
position = callsite.sourcemap.originalPositionFor({
line: getLineNumber.call(callsite),
column: getColumnNumber.call(callsite)
})
} catch (e) {
debug('error fetching source map position: %s', e.message)
return {}
}
}

@@ -300,0 +307,0 @@

{
"name": "stackman",
"version": "2.0.0",
"version": "2.0.1",
"description": "Enhance an error stacktrace with code excerpts and other goodies",

@@ -48,10 +48,10 @@ "main": "index.js",

"coordinates": [
55.6809959,
12.5644639
55.68112989999999,
12.5645466
],
"standard": {
"ignore": [
"/test/fixtures/"
"/test/fixtures/lib/"
]
}
}

@@ -86,2 +86,6 @@ # Stackman

Note that any error related to loading or parsing source maps will be
suppressed. If a source map related error occurs, Stackman behaves as if
the `sourcemap` option is `false`.
Options:

@@ -88,0 +92,0 @@

@@ -5,51 +5,99 @@ 'use strict'

var test = require('tape')
var generateError = require('./fixtures/generateError')
var stackman = require('../')()
test('sourcemapped location getters', function (t) {
var err = generateError()
stackman.callsites(err, function (err, callsites) {
t.error(err)
var callsite = callsites[0]
t.equal(callsite.getFileName(), path.join(__dirname, 'fixtures', 'generateError.original.js'))
t.equal(callsite.getLineNumber(), 2)
t.equal(callsite.getColumnNumber(), 53)
t.end()
test('source maps disabled', function (t) {
var err = require('./fixtures/lib/error')()
stackman.callsites(err, {sourcemap: false}, assertSourceMapNotLoaded.bind(null, t, 'error.js'))
})
test('source map inlined', function (t) {
var err = require('./fixtures/lib/error-inline')()
stackman.callsites(err, assertSourceFound.bind(null, t))
})
test('source map linked', function (t) {
t.test('source mapped source code embedded', function (t) {
var err = require('./fixtures/lib/error-src-embedded')()
stackman.callsites(err, assertSourceFound.bind(null, t))
})
t.test('source mapped source code on disk', function (t) {
var err = require('./fixtures/lib/error')()
stackman.callsites(err, assertSourceFound.bind(null, t))
})
t.test('source mapped source code not found', function (t) {
var err = require('./fixtures/lib/error-src-missing')()
stackman.callsites(err, assertSourceNotFound.bind(null, t))
})
})
test('sourcemapped location getters fall back if no sourcemap exists', function (t) {
stackman.callsites(new Error(), function (err, callsites) {
t.error(err)
var callsite = callsites[0]
t.equal(callsite.getFileName(), __filename)
t.notEqual(callsite.getLineNumber(), 2)
t.notEqual(callsite.getColumnNumber(), 53)
t.end()
test('fails', function (t) {
t.test('inlined source map broken', function (t) {
var err = require('./fixtures/lib/error-inline-broken')()
stackman.callsites(err, assertSourceMapNotLoaded.bind(null, t, 'error-inline-broken.js'))
})
t.test('linked source map not found', function (t) {
var err = require('./fixtures/lib/error-map-missing')()
stackman.callsites(err, assertSourceMapNotLoaded.bind(null, t, 'error-map-missing.js'))
})
t.test('linked source map broken', function (t) {
var err = require('./fixtures/lib/error-broken')()
stackman.callsites(err, assertSourceMapNotLoaded.bind(null, t, 'error-broken.js'))
})
})
test('sourcemapped context', function (t) {
var err = generateError()
stackman.callsites(err, function (err, callsites) {
function assertSourceMapNotLoaded (t, filename, err, callsites) {
t.error(err)
var callsite = callsites[0]
t.equal(callsite.getFileName(), path.join(__dirname, 'fixtures', 'lib', filename))
t.equal(callsite.getRelativeFileName(), path.join('test', 'fixtures', 'lib', filename))
t.equal(callsite.getLineNumber(), 6)
t.equal(callsite.getColumnNumber(), 10)
t.equal(callsite.getFunctionName(), 'generateError')
t.equal(callsite.getFunctionNameSanitized(), 'generateError')
t.equal(callsite.isApp(), __dirname.indexOf('node_modules') === -1)
callsite.sourceContext(function (err, context) {
t.error(err)
callsites[0].sourceContext(function (err, context) {
t.error(err)
t.deepEqual(context, {
pre: ['// Just a little prefixing line'],
line: 'const generateError = (errMessage = \'Some error\') => new Error(errMessage)',
post: ['', 'module.exports = generateError', '']
})
t.end()
})
t.equal(context.line, ' return new Error(msg);')
t.end()
})
})
}
test('callsite.getRelativeFileName()', function (t) {
var err = generateError()
stackman.callsites(err, function (err, callsites) {
function assertSourceFound (t, err, callsites) {
t.error(err)
var callsite = callsites[0]
t.equal(callsite.getFileName(), path.join(__dirname, 'fixtures', 'src', 'error.js'))
t.equal(callsite.getRelativeFileName(), path.join('test', 'fixtures', 'src', 'error.js'))
t.equal(callsite.getLineNumber(), 2)
t.equal(callsite.getColumnNumber(), 39)
t.equal(callsite.getFunctionName(), 'generateError')
t.equal(callsite.getFunctionNameSanitized(), 'generateError')
t.equal(callsite.isApp(), __dirname.indexOf('node_modules') === -1)
callsite.sourceContext(function (err, context) {
t.error(err)
t.equal(callsites[0].getRelativeFileName(), 'test/fixtures/generateError.original.js')
t.deepEqual(context.pre, ['// Just a little prefixing line'])
t.equal(context.line, 'const generateError = (msg = \'foo\') => new Error(msg)')
t.deepEqual(context.post, ['', 'module.exports = generateError', ''])
t.end()
})
})
}
function assertSourceNotFound (t, err, callsites) {
t.error(err)
var callsite = callsites[0]
t.equal(callsite.getFileName(), path.join(__dirname, 'fixtures', 'src', 'not', 'found.js'))
t.equal(callsite.getRelativeFileName(), path.join('test', 'fixtures', 'src', 'not', 'found.js'))
t.equal(callsite.getLineNumber(), 2)
t.equal(callsite.getColumnNumber(), 39)
t.equal(callsite.getFunctionName(), 'generateError')
t.equal(callsite.getFunctionNameSanitized(), 'generateError')
t.equal(callsite.isApp(), __dirname.indexOf('node_modules') === -1)
callsite.sourceContext(function (err, context) {
t.equal(err.code, 'ENOENT')
t.equal(context, undefined)
t.end()
})
}
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