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

stack-trace-parser

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stack-trace-parser - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

example-undefined.js

2

package.json
{
"name": "stack-trace-parser",
"description": "parse stack trace",
"version": "0.0.2",
"version": "0.0.3",
"main": "src/parser.js",

@@ -6,0 +6,0 @@ "dependencies": {},

@@ -40,7 +40,10 @@ var parser = require('../src/parser');

describe('simple stack trace', function() {
var error = {},
parsed;
describe('stack trace', function() {
var error;
beforeEach(function() {
error = {};
});
it('parses the file names from a basic stack trace', function() {
error.stack =

@@ -50,10 +53,27 @@ 'Error: Foo\n' +

' at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)\n';
parsed = parser.parse(error);
expect(parsed[0].fileName).toBe('/Users/hoitz/develop/test.coffee');
expect(parsed[1].fileName).toBe('timers.js');
});
it('parses the file names from a basic stack trace', function() {
expect(parsed[0].fileName).toBe('/Users/hoitz/develop/test.coffee');
expect(parsed[1].fileName).toBe('timers.js');
it('parses type exception type', function() {
error.stack =
'ReferenceError: d is not defined\n' +
' at Object.<anonymous> (/Users/cvig/dev/node-stack-trace-parser/example-undefined.js:5:7)\n' +
' at Module._compile (module.js:456:26)\n' +
' at Object.Module._extensions..js (module.js:474:10)\n' +
' at Module.load (module.js:356:32)\n' +
' at Function.Module._load (module.js:312:12)\n' +
' at Function.Module.runMain (module.js:497:10)\n' +
' at startup (node.js:119:16)\n' +
' at node.js:902:3\n';
parsed = parser.parse(error);
expect(parsed.type).toBe('ReferenceError');
expect(parsed.message).toBe('d is not defined');
});
});
});

@@ -38,5 +38,19 @@ var _ = require('lodash');

var getTypeAndMessage = function(line) {
var typeAndMessageArray = line.split(': ');
return {
type: typeAndMessageArray[0],
message: typeAndMessageArray[1]
};
};
module.exports = {
parse: function(error) {
return error.stack.split('\n').slice(1).map(this.parseLine);
var lines = error.stack.split('\n');
var typeAndMessage = getTypeAndMessage(lines[0]);
var parsedLines = lines.slice(1).map(this.parseLine);
return _.extend(typeAndMessage, parsedLines);
},

@@ -43,0 +57,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