@@ -6,53 +6,55 @@ import {
66 IStackFrame
77} from '@exceptionless/core' ;
88
9- import * as TraceKit from 'TraceKit' ;
9+ import {
10+ fromError ,
11+ StackFrame
12+ } from 'stacktrace-js' ;
1013
1114export class DefaultErrorParser implements IErrorParser {
12- public parse ( context : EventPluginContext , exception : Error ) : IError {
15+ public async parse ( context : EventPluginContext , exception : Error ) : Promise < IError > {
1316 function getParameters ( parameters : string | string [ ] ) : IParameter [ ] {
1417 const params : string [ ] = ( typeof parameters === 'string' ? [ parameters ] : parameters ) || [ ] ;
1518
16- const result : IParameter [ ] = [ ] ;
19+ const items : IParameter [ ] = [ ] ;
1720 for ( const param of params ) {
18- result . push ( { name : param } ) ;
21+ items . push ( { name : param } ) ;
1922 }
2023
21- return result ;
24+ return items ;
2225 }
2326
24- function getStackFrames ( stackFrames : TraceKit . StackFrame [ ] ) : IStackFrame [ ] {
27+ function getStackFrames ( stackFrames : StackFrame [ ] ) : IStackFrame [ ] {
2528 const ANONYMOUS : string = '<anonymous>' ;
2629 const frames : IStackFrame [ ] = [ ] ;
2730
2831 for ( const frame of stackFrames ) {
32+ const fileName : string = frame . getFileName ( ) ;
2933 frames . push ( {
30- name : ( frame . func || ANONYMOUS ) . replace ( '?' , ANONYMOUS ) ,
31- parameters : getParameters ( frame . args ) ,
32- file_name : frame . url ,
33- line_number : frame . line || 0 ,
34- column : frame . column || 0
34+ name : ( frame . getFunctionName ( ) || ANONYMOUS ) . replace ( '?' , ANONYMOUS ) ,
35+ parameters : getParameters ( frame . getArgs ( ) ) ,
36+ file_name : fileName ,
37+ line_number : frame . getLineNumber ( ) || 0 ,
38+ column : frame . getColumnNumber ( ) || 0 ,
39+ data : {
40+ is_native : frame . getIsNative ( ) || ( fileName && fileName [ 0 ] !== '/' && fileName [ 0 ] !== '.' )
41+ }
3542 } ) ;
3643 }
3744
3845 return frames ;
3946 }
4047
41- const TRACEKIT_STACK_TRACE_KEY : string = '@@_TraceKit.StackTrace' ; // optimization for minifier.
42-
43- const stackTrace : TraceKit . StackTrace = context . contextData [ TRACEKIT_STACK_TRACE_KEY ]
44- ? context . contextData [ TRACEKIT_STACK_TRACE_KEY ]
45- : TraceKit . computeStackTrace ( exception , 25 ) ;
46-
47- if ( ! stackTrace ) {
48- throw new Error ( 'Unable to parse the exceptions stack trace.' ) ;
48+ const result : StackFrame [ ] = await fromError ( exception ) ;
49+ if ( ! result ) {
50+ throw new Error ( 'Unable to parse the exception stack trace.' ) ;
4951 }
5052
51- const message = typeof ( exception ) === 'string' ? exception as any : undefined ;
52- return {
53- type : stackTrace . name || 'Error' ,
54- message : stackTrace . message || exception . message || message ,
55- stack_trace : getStackFrames ( stackTrace . stack || [ ] )
56- } ;
53+ // TODO: Test with reference error.
54+ return Promise . resolve ( {
55+ type : exception . name || 'Error' ,
56+ message : exception . message ,
57+ stack_trace : getStackFrames ( result || [ ] )
58+ } ) ;
5759 }
5860}
0 commit comments