Skip to content

Commit a09f317

Browse files
author
farfromrefug
committed
fix: some stackTrace handling fix
1 parent 0c719d3 commit a09f317

File tree

3 files changed

+39
-34
lines changed

3 files changed

+39
-34
lines changed

src/client.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
6060
// - stack with only the JS error stack
6161
// stackTrace with a mix of JS/Java error
6262
exception['stacktrace'] = exception.toString() + '\n at ' + exception['stack'];
63-
// console.log('eventFromException', exception['stack']);
64-
// console.log('eventFromException1', exception['stackTrace']);
6563
} else if (exception['stackTrace']) {
6664
exception['stacktrace'] = exception['stackTrace'];
6765
}
@@ -73,17 +71,21 @@ export class NativescriptClient extends BaseClient<NativescriptClientOptions> {
7371
this._options.attachStacktrace,
7472
);
7573
if(exception['nativeException']) {
76-
const stack = parseErrorStack({ stack: 'at ' + exception['stackTrace'] } as any).filter(f=>f.platform !== 'javascript');
77-
stack.forEach((frame) => rewriteFrameIntegration._iteratee(frame));
78-
event.exception.values.unshift({
79-
type:'NativeException',
80-
value:exception.toString(),
81-
stacktrace:{
82-
frames:stack
83-
}
84-
});
74+
try {
75+
const stack = parseErrorStack({ stack: 'at ' + exception['stackTrace'] } as any).filter(f=>f.platform !== 'javascript');
76+
stack.forEach((frame) => rewriteFrameIntegration._iteratee(frame));
77+
event.exception.values.unshift({
78+
type:'NativeException',
79+
value:exception.toString(),
80+
stacktrace:{
81+
frames:stack
82+
}
83+
});
84+
} catch (error) {
85+
console.error(error, error.stack);
86+
}
87+
8588
}
86-
// event.exception.values.forEach(ex=>console.log('event.exception.values', JSON.stringify(ex.stacktrace.frames.reverse())));
8789
return event;
8890
// return this._browserClient.eventFromException(exception, hint);
8991
}

src/integrations/default.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,35 @@ export let rewriteFrameIntegration: {
3232
*/
3333
export function getDefaultIntegrations(options: NativescriptClientOptions & NativescriptOptions): Integration[] {
3434
const integrations: Integration[] = [];
35+
const iteratee = (frame: StackFrame) => {
36+
if (frame.platform === 'javascript' && frame.filename) {
37+
let filename = frame.filename
38+
.replace(/^file\:\/\//, '')
39+
.replace(/^address at /, '')
40+
.replace(/^.*\/[^\.]+(\.app|CodePush|.*(?=\/))/, '');
3541

36-
rewriteFrameIntegration = new RewriteFrames({
37-
iteratee: (frame: StackFrame) => {
38-
if (frame.platform === 'javascript' && frame.filename) {
39-
let filename = frame.filename
40-
.replace(/^file\:\/\//, '')
41-
.replace(/^address at /, '')
42-
.replace(/^.*\/[^\.]+(\.app|CodePush|.*(?=\/))/, '');
43-
44-
if (frame.filename.indexOf('[native code]') === -1) {
45-
const appPrefix = options.appPrefix ?? '~/';
46-
if (appPrefix.endsWith('//') && !appPrefix.endsWith('///')) {
47-
filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename}` : `${appPrefix}/${filename}`;
48-
} else {
49-
filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename.slice(1)}` : `${appPrefix}${filename}`;
50-
}
42+
if (frame.filename.indexOf('[native code]') === -1) {
43+
const appPrefix = options.appPrefix ?? '~/';
44+
if (appPrefix.endsWith('//') && !appPrefix.endsWith('///')) {
45+
filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename}` : `${appPrefix}/${filename}`;
46+
} else {
47+
filename = filename.indexOf('/') === 0 ? `${appPrefix}${filename.slice(1)}` : `${appPrefix}${filename}`;
5148
}
49+
}
5250

53-
frame.filename = filename;
54-
if (options.colnoOffset) {
55-
frame.colno += options.colnoOffset;
56-
}
57-
// We always want to have a tripple slash
51+
frame.filename = filename;
52+
if (options.colnoOffset) {
53+
frame.colno += options.colnoOffset;
5854
}
59-
return frame;
55+
// We always want to have a tripple slash
6056
}
57+
return frame;
58+
};
59+
60+
rewriteFrameIntegration = new RewriteFrames({
61+
6162
}) as any;
63+
rewriteFrameIntegration._iteratee =iteratee;
6264

6365
// if (notWeb()) {
6466
integrations.push(

src/sdk.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ export function init(passedOptions: NativescriptOptions): void {
124124
typeof options.tracesSampler !== 'undefined' ||
125125
typeof options.tracesSampleRate !== 'undefined';
126126

127+
const DEFAULT_INTEGRATIONS = getDefaultIntegrations(options);
127128
const defaultIntegrations: false | Integration[] = passedOptions.defaultIntegrations === undefined
128-
? getDefaultIntegrations(options)
129+
? DEFAULT_INTEGRATIONS
129130
: passedOptions.defaultIntegrations;
130131
// if (passedOptions.defaultIntegrations === undefined) {
131132
// rewriteFrameIntegration = new RewriteFrames({

0 commit comments

Comments
 (0)