@@ -19,6 +19,18 @@ import { NativescriptTracing } from './tracing';
1919import { rewriteFrameIntegration } from './integrations/default' ;
2020import { parseErrorStack } from './integrations/debugsymbolicator' ;
2121
22+ function wrapNativeException ( ex , errorType = typeof ex ) {
23+ if ( __ANDROID__ && ! ( ex instanceof Error ) && errorType === 'object' ) {
24+ const err = new Error ( ex . toString ( ) ) ;
25+ err [ 'nativeException' ] = ex ;
26+ //@ts -ignore
27+ err [ 'stackTrace' ] = com . tns . NativeScriptException . getStackTraceAsString ( ex ) ;
28+ return err ;
29+ }
30+ return ex ;
31+ }
32+ const FATAL_ERROR_REGEXP = / N a t i v e S c r i p t e n c o u n t e r e d a f a t a l e r r o r : ( [ ^ ] * ?) a t ( [ \t \n \s ] * ) ? ( [ ^ ] * ) $ / m;
33+
2234/**
2335 * The Sentry React Native SDK Client.
2436 *
@@ -54,14 +66,31 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
5466 * @inheritDoc
5567 */
5668 public async eventFromException ( exception : unknown , hint ?: EventHint ) : Promise < Event > {
69+ exception = wrapNativeException ( exception ) ;
5770 // N put stackTrace in "stackTrace" instead of "stacktrace"
58- if ( exception [ 'nativeException' ] ) {
71+ if ( __ANDROID__ && exception [ 'nativeException' ] ) {
5972 // in case of nativeException we have:
6073 // - stack with only the JS error stack
6174 // stackTrace with a mix of JS/Java error
6275 exception [ 'stacktrace' ] = exception . toString ( ) + '\n at ' + exception [ 'stack' ] ;
6376 } else if ( exception [ 'stackTrace' ] ) {
64- exception [ 'stacktrace' ] = exception [ 'stackTrace' ] ;
77+ if ( __IOS__ ) {
78+ exception [ 'stacktrace' ] = exception [ 'stack' ] ;
79+
80+ // const stackTrace = exception['stackTrace'];
81+ // const matches = stackTrace.match(FATAL_ERROR_REGEXP);
82+ // console.log('matches', stackTrace, matches);
83+ // if (matches) {
84+ // const errorMessage = matches[1];
85+ // const jsStackTrace = stackTrace.substring(stackTrace.indexOf(matches[2]));
86+ // // const stack = parseErrorStack({ stack: 'at ' + jsStackTrace } as any).reverse();
87+ // exception['stacktrace'] = errorMessage + '\n at ' + jsStackTrace;
88+ // } else {
89+ // exception['stacktrace'] = stackTrace;
90+ // }
91+ } else {
92+ exception [ 'stacktrace' ] = exception [ 'stackTrace' ] ;
93+ }
6594 }
6695 const hintWithScreenshot = Screenshot . attachScreenshotToEventHint ( hint , this . _options ) ;
6796 const event = await eventFromException ( this . _options . stackParser , exception , hintWithScreenshot , this . _options . attachStacktrace ) ;
@@ -81,9 +110,10 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
81110 }
82111 } else if ( __IOS__ && exception [ 'stackTrace' ] ) {
83112 try {
84- const stack = parseErrorStack ( { stack : 'at ' + exception [ 'stackTrace' ] } as any ) . filter ( ( f ) => f . platform !== 'javascript' ) ;
113+ // const stack = parseErrorStack({ stack: 'at ' + exception['stackTrace'] } as any).filter((f) => f.platform !== 'javascript');
85114 // stack.forEach((frame) => rewriteFrameIntegration._iteratee(frame));
86- event . exception . values [ 0 ] . stacktrace . frames . forEach ( ( frame ) => rewriteFrameIntegration . _iteratee ( frame ) ) ;
115+ // event.exception.values[0].stacktrace.frames.forEach((frame) => rewriteFrameIntegration._iteratee(frame));
116+ // event.exception.values[0].stacktrace.frames = event.exception.values[0].stacktrace.frames.reverse();
87117 // event.exception.values.unshift({
88118 // type: 'NativeException',
89119 // value: exception.toString(),
0 commit comments