1- import { IError } from '../../models/IError' ;
2- import { IStackFrame } from '../../models/IStackFrame' ;
31import { IEventPlugin } from '../IEventPlugin' ;
42import { EventPluginContext } from '../EventPluginContext' ;
53
@@ -22,101 +20,12 @@ export class ErrorPlugin implements IEventPlugin {
2220 return Promise . resolve ( ) ;
2321 }
2422
25- return StackTrace . fromError ( exception ) . then (
26- ( stackFrames : StackTrace . StackFrame [ ] ) => this . processError ( context , exception , stackFrames ) ,
27- ( ) => this . onParseError ( context )
28- ) ;
29- }
30-
31- private processError ( context :EventPluginContext , exception :Error , stackFrames : StackTrace . StackFrame [ ] ) : Promise < any > {
32- var error :IError = {
33- message : exception . message ,
34- stack_trace : this . getStackFrames ( context , stackFrames || [ ] )
35- } ;
36-
37- context . event . data [ '@error' ] = error ;
38-
39- return Promise . resolve ( ) ;
40- }
41-
42- private onParseError ( context :EventPluginContext ) : Promise < any > {
43- context . cancel = true ;
44- return Promise . reject ( new Error ( 'Unable to parse the exceptions stack trace. This exception will be discarded.' ) )
45- }
46-
47- private getStackFrames ( context :EventPluginContext , stackFrames :StackTrace . StackFrame [ ] ) : IStackFrame [ ] {
48- var frames :IStackFrame [ ] = [ ] ;
49-
50- for ( var index = 0 ; index < stackFrames . length ; index ++ ) {
51- frames . push ( {
52- name : stackFrames [ index ] . functionName ,
53- //parameters: stackFrames[index].args, // TODO: need to verify arguments.
54- file_name : stackFrames [ index ] . fileName ,
55- line_number : stackFrames [ index ] . lineNumber ,
56- column : stackFrames [ index ] . columnNumber
57- } ) ;
23+ var parser = context . client . config . errorParser ;
24+ if ( ! parser ) {
25+ context . cancel = true ;
26+ return Promise . reject ( new Error ( 'No error parser was defined. This exception will be discarded.' ) )
5827 }
5928
60- return frames ;
61- }
62- }
63-
64- declare module StackTrace {
65- interface StackTraceOptions {
66- filter ?: ( stackFrame :StackFrame ) => boolean ;
67- sourceCache ?: { URL :string } ;
68- offline ?: boolean ;
69- }
70-
71- interface StackFrame {
72- constructor ( functionName :string , args :any , fileName :string , lineNumber :number , columnNumber :number ) ;
73-
74- functionName ?:string ;
75- args ?:any ;
76- fileName ?:string ;
77- lineNumber ?:number ;
78- columnNumber ?:number ;
79- toString ( ) :string ;
29+ return parser . parse ( context , context . event . data [ '@error' ] ) ;
8030 }
81-
82- /**
83- * Get a backtrace from invocation point.
84- * @param options Options Object
85- * @return Array[StackFrame]
86- */
87- function get ( options : StackTraceOptions ) : Promise < StackFrame [ ] > ;
88-
89- /**
90- * Given an error object, parse it.
91- * @param error Error object
92- * @param options Object for options
93- * @return Array[StackFrame]
94- */
95- function fromError ( error :Error , options ?:StackTraceOptions ) : Promise < StackFrame [ ] > ;
96-
97- /**
98- * Use StackGenerator to generate a backtrace.
99- * @param options Object options
100- * @returns Array[StackFrame]
101- */
102- function generateArtificially ( options : StackTraceOptions ) : Promise < StackFrame [ ] > ;
103-
104- /**
105- * Given a function, wrap it such that invocations trigger a callback that
106- * is called with a stack trace.
107- *
108- * @param {Function } fn to be instrumented
109- * @param {Function } callback function to call with a stack trace on invocation
110- * @param {Function } errorCallback optional function to call with error if unable to get stack trace.
111- * @param {Object } thisArg optional context object (e.g. window)
112- */
113- function instrument ( fn :( ) => void , callback :( stackFrames :StackFrame [ ] ) => void , errorCallback :( ) => void , thisArg :any ) : void ;
114-
115- /**
116- * Given a function that has been instrumented,
117- * revert the function to it's original (non-instrumented) state.
118- *
119- * @param fn {Function}
120- */
121- function deinstrument ( fn :( ) => void ) : void ;
12231}
0 commit comments