forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeErrorParser.ts
More file actions
43 lines (37 loc) · 1.23 KB
/
NodeErrorParser.ts
File metadata and controls
43 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { parse as fromError } from "stack-trace";
import {
ErrorInfo,
EventPluginContext,
IErrorParser,
StackFrameInfo,
} from "@exceptionless/core";
export class NodeErrorParser implements IErrorParser {
public parse(context: EventPluginContext, exception: Error): Promise<ErrorInfo> {
function getStackFrames(stackFrames: any[]): StackFrameInfo[] {
const frames: StackFrameInfo[] = [];
for (const frame of stackFrames) {
frames.push({
name: frame.methodName || frame.functionName,
parameters: [], // TODO: See if there is a way to get this.
file_name: frame.fileName,
line_number: frame.lineNumber || 0,
column: frame.columnNumber || 0,
declaring_type: frame.typeName,
data: {
is_native: frame.native || (frame.fileName && frame.fileName[0] !== "/" && frame.fileName[0] !== "."),
},
});
}
return frames;
}
const result = fromError(exception);
if (!result) {
throw new Error("Unable to parse the exception stack trace.");
}
return Promise.resolve({
type: exception.name || "Error",
message: exception.message,
stack_trace: getStackFrames(result || []),
});
}
}