Skip to content

Commit dd415cb

Browse files
committed
fix: major update of the android sdk
Use latest Catch JS stack when a native exception is catched on the java side
1 parent aee49fc commit dd415cb

File tree

8 files changed

+3563
-1236
lines changed

8 files changed

+3563
-1236
lines changed
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11

22
dependencies {
3-
compile 'org.slf4j:slf4j-nop:1.7.25'
4-
implementation 'io.sentry:sentry-android:1.7.29'
3+
api 'io.sentry:sentry-android:2.1.0-alpha.1'
54
}
6-
7-
android.applicationVariants.all { variant ->
8-
if (variant.buildType.name == 'release') {
9-
variant.mergeAssets.doLast {
10-
println("deleting source map files from variant")
11-
delete(fileTree(dir: variant.mergeAssets.outputDir, includes: ['**/*.map']))
12-
}
13-
}
14-
}

src/backend.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ export interface NativescriptOptions extends BrowserOptions {
3333
shutdownTimeout?: number;
3434

3535
/** Should the native nagger alert be shown or not. */
36-
enableNativeNagger?: boolean;
36+
// enableNativeNagger?: boolean;
3737
/**
3838
* Optional prefix to add while rewriting frames
3939
*/
4040
appPrefix?: string;
41+
42+
traceErrorHandler?: boolean;
43+
uncaughtErrors?: boolean;
4144
}
4245

4346
/** The Sentry Nativescript SDK Backend. */

src/client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class NativescriptClient extends BaseClient<NativescriptBackend, Nativesc
2424
* @inheritDoc
2525
*/
2626
protected _prepareEvent(event: Event, scope?: Scope, hint?: EventHint): SyncPromise<Event | null> {
27-
// console.log('_prepareEvent', hint);
2827
event.platform = event.platform || 'javascript';
2928
event.sdk = {
3029
...event.sdk,

src/integrations/debugsymbolicator.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type NativescriptError = Error & {
3333
// ...
3434
// };
3535

36-
function parseErrorStack(e: NativescriptError): StackFrame[] {
36+
export function parseErrorStack(e: NativescriptError): StackFrame[] {
3737
if (!e || !e.stack) {
3838
return [];
3939
}
@@ -47,6 +47,29 @@ function parseErrorStack(e: NativescriptError): StackFrame[] {
4747
}));
4848
}
4949
}
50+
51+
/**
52+
* Converts NativescriptFrames to frames in the Sentry format
53+
* @param frames NativescriptFrame[]
54+
*/
55+
export function convertNativescriptFramesToSentryFrames(frames: NativescriptFrame[]): StackFrame[] {
56+
// Below you will find lines marked with :HACK to prevent showing errors in the sentry ui
57+
// But since this is a debug only feature: This is Fine (TM)
58+
return frames.map(
59+
(frame: NativescriptFrame): StackFrame => {
60+
const inApp = (frame.file && !frame.file.includes('node_modules')) || (!!frame.column && !!frame.lineNumber);
61+
// const inApp =true;
62+
return {
63+
colno: frame.column,
64+
filename: frame.file,
65+
function: frame.methodName,
66+
in_app: inApp,
67+
lineno: inApp ? frame.lineNumber : undefined, // :HACK
68+
platform: inApp ? 'javascript' : 'node' // :HACK
69+
};
70+
}
71+
);
72+
}
5073
/** Tries to symbolicate the JS stack trace on the device. */
5174
export class DebugSymbolicator implements Integration {
5275
/**
@@ -67,7 +90,6 @@ export class DebugSymbolicator implements Integration {
6790
if (!self || hint === undefined || hint.originalException === undefined) {
6891
return event;
6992
}
70-
7193
const error: NativescriptError = hint.originalException as any;
7294

7395
// const parseErrorStack = require('react-native/Libraries/Core/Devtools/parseErrorStack');
@@ -84,7 +106,7 @@ export class DebugSymbolicator implements Integration {
84106
// await self._symbolicate(event, stack);
85107
// }
86108
// if (reactError.jsEngine === 'hermes') {
87-
const convertedFrames = this._convertNativescriptFramesToSentryFrames(stack as any);
109+
const convertedFrames = convertNativescriptFramesToSentryFrames(stack as any);
88110
this._replaceFramesInEvent(event, convertedFrames);
89111
// }
90112

@@ -114,29 +136,6 @@ export class DebugSymbolicator implements Integration {
114136
}
115137
}
116138

117-
/**
118-
* Converts NativescriptFrames to frames in the Sentry format
119-
* @param frames NativescriptFrame[]
120-
*/
121-
private _convertNativescriptFramesToSentryFrames(frames: NativescriptFrame[]): StackFrame[] {
122-
// Below you will find lines marked with :HACK to prevent showing errors in the sentry ui
123-
// But since this is a debug only feature: This is Fine (TM)
124-
return frames.map(
125-
(frame: NativescriptFrame): StackFrame => {
126-
const inApp = (frame.file && !frame.file.includes('node_modules')) || (!!frame.column && !!frame.lineNumber);
127-
// const inApp =true;
128-
return {
129-
colno: frame.column,
130-
filename: frame.file,
131-
function: frame.methodName,
132-
in_app: inApp,
133-
lineno: inApp ? frame.lineNumber : undefined, // :HACK
134-
platform: inApp ? 'javascript' : 'node' // :HACK
135-
};
136-
}
137-
);
138-
}
139-
140139
/**
141140
* Replaces the frames in the exception of a error.
142141
* @param event Event

src/integrations/nativescripterrorhandlers.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import { Integration, Severity } from '@sentry/types';
3+
import { NSSentry } from '../nssentry';
34
import { logger } from '@sentry/utils';
45

56
import { NativescriptClient } from '../client';
@@ -8,9 +9,9 @@ import * as application from '@nativescript/core/application';
89
import * as trace from '@nativescript/core/trace';
910

1011
/** NativescriptErrorHandlers Options */
11-
interface NativescriptErrorHandlersOptions {
12-
onerror: boolean;
13-
onunhandledrejection: boolean;
12+
export interface NativescriptErrorHandlersOptions {
13+
traceErrorHandler?: boolean;
14+
uncaughtErrors?: boolean;
1415
}
1516

1617
declare const global: any;
@@ -33,8 +34,8 @@ export class NativescriptErrorHandlers implements Integration {
3334
/** Constructor */
3435
public constructor(options?: NativescriptErrorHandlersOptions) {
3536
this._options = {
36-
onerror: true,
37-
onunhandledrejection: true,
37+
traceErrorHandler: false,
38+
uncaughtErrors: false,
3839
...options
3940
};
4041
}
@@ -51,7 +52,7 @@ export class NativescriptErrorHandlers implements Integration {
5152
* Handle Promises
5253
*/
5354
private _handleUnhandledRejections(): void {
54-
if (this._options.onunhandledrejection) {
55+
if (this._options.uncaughtErrors) {
5556
application.on(application.uncaughtErrorEvent, this.globalHanderEvent, this);
5657
// const tracking = require('promise/setimmediate/rejection-tracking');
5758
// tracking.disable();
@@ -97,13 +98,19 @@ export class NativescriptErrorHandlers implements Integration {
9798
getCurrentHub().captureException(error, {
9899
originalException: error
99100
});
101+
// const timeout = client.getOptions().shutdownTimeout || 2000;
102+
// NSSentry.flush(timeout);
103+
// getCurrentHub()
104+
// .getClient()
105+
// .flush(2000);
100106
});
101107

102108
const client = getCurrentHub().getClient<NativescriptClient>();
103109
// If in dev, we call the default handler anyway and hope the error will be sent
104110
// Just for a better dev experience
105111
if (client) {
106-
(client.flush(client.getOptions().shutdownTimeout || 2000) as any)
112+
const timeout = client.getOptions().shutdownTimeout || 2000;
113+
(client.flush(timeout) as Promise<any>)
107114
.then(() => {
108115
// defaultHandler(error, isFatal);
109116
})
@@ -120,7 +127,7 @@ export class NativescriptErrorHandlers implements Integration {
120127
* Handle erros
121128
*/
122129
private _handleOnError(): void {
123-
if (this._options.onerror) {
130+
if (this._options.traceErrorHandler) {
124131
// let handlingFatal = false;
125132
application.on(application.discardedErrorEvent, this.globalHanderEvent, this);
126133

0 commit comments

Comments
 (0)