Skip to content

Commit 15c80ab

Browse files
fix(frames): remove non absolute non url frame.abs_path coming from default stack parser (#2891)
1 parent 8a53c0d commit 15c80ab

File tree

4 files changed

+756
-25
lines changed

4 files changed

+756
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixes
6+
7+
- Remove non URL `frame.abs_path` which was causing source maps to fail ([#2891](https://github.com/getsentry/sentry-react-native/pull/2891))
8+
59
### Dependencies
610

711
- Bump Cocoa SDK from v8.2.0 to v8.3.0 ([#2876](https://github.com/getsentry/sentry-react-native/pull/2876))

src/js/integrations/rewriteframes.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { RewriteFrames } from '@sentry/integrations';
2+
import type { StackFrame } from '@sentry/types';
3+
4+
/**
5+
* Creates React Native default rewrite frames integration
6+
* which appends app:// to the beginning of the filename
7+
* and removes file://, 'address at' prefixes and CodePush postfix.
8+
*/
9+
export function createReactNativeRewriteFrames(): RewriteFrames {
10+
return new RewriteFrames({
11+
iteratee: (frame: StackFrame) => {
12+
if (frame.filename) {
13+
frame.filename = frame.filename
14+
.replace(/^file:\/\//, '')
15+
.replace(/^address at /, '')
16+
.replace(/^.*\/[^.]+(\.app|CodePush|.*(?=\/))/, '');
17+
18+
if (
19+
frame.filename !== '[native code]' &&
20+
frame.filename !== 'native'
21+
) {
22+
const appPrefix = 'app://';
23+
// We always want to have a triple slash
24+
frame.filename =
25+
frame.filename.indexOf('/') === 0
26+
? `${appPrefix}${frame.filename}`
27+
: `${appPrefix}/${frame.filename}`;
28+
}
29+
delete frame.abs_path;
30+
}
31+
return frame;
32+
},
33+
});
34+
}

src/js/sdk.tsx

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import type { Scope } from '@sentry/core';
22
import { getIntegrationsToSetup, Hub, initAndBind, makeMain, setExtra } from '@sentry/core';
3-
import { RewriteFrames } from '@sentry/integrations';
43
import {
54
defaultIntegrations as reactDefaultIntegrations,
65
defaultStackParser,
76
getCurrentHub,
87
makeFetchTransport,
98
} from '@sentry/react';
10-
import type { Integration, StackFrame, UserFeedback } from '@sentry/types';
9+
import type { Integration, UserFeedback } from '@sentry/types';
1110
import { logger, stackParserFromStackParserOptions } from '@sentry/utils';
1211
import * as React from 'react';
1312

@@ -22,6 +21,7 @@ import {
2221
Release,
2322
SdkInfo,
2423
} from './integrations';
24+
import { createReactNativeRewriteFrames } from './integrations/rewriteframes';
2525
import { Screenshot } from './integrations/screenshot';
2626
import { ViewHierarchy } from './integrations/viewhierarchy';
2727
import type { ReactNativeClientOptions, ReactNativeOptions, ReactNativeWrapperOptions } from './options';
@@ -107,29 +107,7 @@ export function init(passedOptions: ReactNativeOptions): void {
107107
defaultIntegrations.push(new DebugSymbolicator());
108108
}
109109

110-
defaultIntegrations.push(new RewriteFrames({
111-
iteratee: (frame: StackFrame) => {
112-
if (frame.filename) {
113-
frame.filename = frame.filename
114-
.replace(/^file:\/\//, '')
115-
.replace(/^address at /, '')
116-
.replace(/^.*\/[^.]+(\.app|CodePush|.*(?=\/))/, '');
117-
118-
if (
119-
frame.filename !== '[native code]' &&
120-
frame.filename !== 'native'
121-
) {
122-
const appPrefix = 'app://';
123-
// We always want to have a triple slash
124-
frame.filename =
125-
frame.filename.indexOf('/') === 0
126-
? `${appPrefix}${frame.filename}`
127-
: `${appPrefix}/${frame.filename}`;
128-
}
129-
}
130-
return frame;
131-
},
132-
}));
110+
defaultIntegrations.push(createReactNativeRewriteFrames());
133111
if (options.enableNative) {
134112
defaultIntegrations.push(new DeviceContext());
135113
}

0 commit comments

Comments
 (0)