Skip to content

Commit d2c9600

Browse files
committed
fix: Rename stack-trace file
1 parent 1dda724 commit d2c9600

File tree

5 files changed

+272
-271
lines changed

5 files changed

+272
-271
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ since we removed some methods from the public API and removed some classes from
4646
- [opentracing] feat: Introduce `@sentry/opentracing` providing functions to attach opentracing data to Sentry Events
4747
- **breaking** [core] ref: `Dedupe` Integration is now optional, it is no longer enabled by default.
4848
- **breaking** [core] ref: Removed default client fingerprinting for messages
49+
- [node] ref: Remove stack-trace dependencies
4950

5051
## 4.6.4
5152

packages/node/src/parsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { readFile } from 'fs';
66
import { LRUMap } from 'lru_map';
77

88
import { NodeOptions } from './backend';
9-
import * as stacktrace from './stack-trace';
9+
import * as stacktrace from './stacktrace';
1010

1111
// tslint:disable-next-line:no-unsafe-any
1212
const DEFAULT_LINES_OF_CONTEXT: number = 7;
Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,99 @@
1-
/**
2-
* stack-trace - Parses node.js stack traces
3-
*
4-
* This was originally forked to fix this issue:
5-
* https://github.com/felixge/node-stack-trace/issues/31
6-
*
7-
* Mar 19,2019 - #4fd379e
8-
*
9-
* https://github.com/felixge/node-stack-trace/
10-
* @license MIT
11-
*/
12-
13-
/** Decoded StackFrame */
14-
export interface StackFrame {
15-
fileName: string;
16-
lineNumber: number;
17-
functionName: string;
18-
typeName: string;
19-
methodName: string;
20-
native: boolean;
21-
columnNumber: number;
22-
}
23-
24-
/** Extracts StackFrames fron the Error */
25-
export function parse(err: Error): StackFrame[] {
26-
if (!err.stack) {
27-
return [];
28-
}
29-
30-
const lines = err.stack.split('\n').slice(1);
31-
32-
return lines
33-
.map(line => {
34-
if (line.match(/^\s*[-]{4,}$/)) {
35-
return {
36-
columnNumber: null,
37-
fileName: line,
38-
functionName: null,
39-
lineNumber: null,
40-
methodName: null,
41-
native: null,
42-
typeName: null,
43-
};
44-
}
45-
46-
const lineMatch = line.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/);
47-
if (!lineMatch) {
48-
return undefined;
49-
}
50-
51-
let object = null;
52-
let method = null;
53-
let functionName = null;
54-
let typeName = null;
55-
let methodName = null;
56-
const isNative = lineMatch[5] === 'native';
57-
58-
if (lineMatch[1]) {
59-
functionName = lineMatch[1];
60-
let methodStart = functionName.lastIndexOf('.');
61-
if (functionName[methodStart - 1] === '.') {
62-
methodStart--;
63-
}
64-
if (methodStart > 0) {
65-
object = functionName.substr(0, methodStart);
66-
method = functionName.substr(methodStart + 1);
67-
const objectEnd = object.indexOf('.Module');
68-
if (objectEnd > 0) {
69-
functionName = functionName.substr(objectEnd + 1);
70-
object = object.substr(0, objectEnd);
71-
}
72-
}
73-
typeName = null;
74-
}
75-
76-
if (method) {
77-
typeName = object;
78-
methodName = method;
79-
}
80-
81-
if (method === '<anonymous>') {
82-
methodName = null;
83-
functionName = null;
84-
}
85-
86-
const properties = {
87-
columnNumber: parseInt(lineMatch[4], 10) || null,
88-
fileName: lineMatch[2] || null,
89-
functionName,
90-
lineNumber: parseInt(lineMatch[3], 10) || null,
91-
methodName,
92-
native: isNative,
93-
typeName,
94-
};
95-
96-
return properties;
97-
})
98-
.filter(callSite => !!callSite) as StackFrame[];
99-
}
1+
/**
2+
* stack-trace - Parses node.js stack traces
3+
*
4+
* This was originally forked to fix this issue:
5+
* https://github.com/felixge/node-stack-trace/issues/31
6+
*
7+
* Mar 19,2019 - #4fd379e
8+
*
9+
* https://github.com/felixge/node-stack-trace/
10+
* @license MIT
11+
*/
12+
13+
/** Decoded StackFrame */
14+
export interface StackFrame {
15+
fileName: string;
16+
lineNumber: number;
17+
functionName: string;
18+
typeName: string;
19+
methodName: string;
20+
native: boolean;
21+
columnNumber: number;
22+
}
23+
24+
/** Extracts StackFrames fron the Error */
25+
export function parse(err: Error): StackFrame[] {
26+
if (!err.stack) {
27+
return [];
28+
}
29+
30+
const lines = err.stack.split('\n').slice(1);
31+
32+
return lines
33+
.map(line => {
34+
if (line.match(/^\s*[-]{4,}$/)) {
35+
return {
36+
columnNumber: null,
37+
fileName: line,
38+
functionName: null,
39+
lineNumber: null,
40+
methodName: null,
41+
native: null,
42+
typeName: null,
43+
};
44+
}
45+
46+
const lineMatch = line.match(/at (?:(.+?)\s+\()?(?:(.+?):(\d+)(?::(\d+))?|([^)]+))\)?/);
47+
if (!lineMatch) {
48+
return undefined;
49+
}
50+
51+
let object = null;
52+
let method = null;
53+
let functionName = null;
54+
let typeName = null;
55+
let methodName = null;
56+
const isNative = lineMatch[5] === 'native';
57+
58+
if (lineMatch[1]) {
59+
functionName = lineMatch[1];
60+
let methodStart = functionName.lastIndexOf('.');
61+
if (functionName[methodStart - 1] === '.') {
62+
methodStart--;
63+
}
64+
if (methodStart > 0) {
65+
object = functionName.substr(0, methodStart);
66+
method = functionName.substr(methodStart + 1);
67+
const objectEnd = object.indexOf('.Module');
68+
if (objectEnd > 0) {
69+
functionName = functionName.substr(objectEnd + 1);
70+
object = object.substr(0, objectEnd);
71+
}
72+
}
73+
typeName = null;
74+
}
75+
76+
if (method) {
77+
typeName = object;
78+
methodName = method;
79+
}
80+
81+
if (method === '<anonymous>') {
82+
methodName = null;
83+
functionName = null;
84+
}
85+
86+
const properties = {
87+
columnNumber: parseInt(lineMatch[4], 10) || null,
88+
fileName: lineMatch[2] || null,
89+
functionName,
90+
lineNumber: parseInt(lineMatch[3], 10) || null,
91+
methodName,
92+
native: isNative,
93+
typeName,
94+
};
95+
96+
return properties;
97+
})
98+
.filter(callSite => !!callSite) as StackFrame[];
99+
}

packages/node/test/parsers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs';
22

33
import * as Parsers from '../src/parsers';
4-
import * as stacktrace from '../src/stack-trace';
4+
import * as stacktrace from '../src/stacktrace';
55

66
import { getError } from './helper/error';
77

0 commit comments

Comments
 (0)