Skip to content

Commit abb7058

Browse files
fix(hermes): Convert Hermes bytecode col pos to 1-based format (#3283)
1 parent 4cc74aa commit abb7058

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
- Create profiles for start up transactions ([#3281](https://github.com/getsentry/sentry-react-native/pull/3281))
8+
- Fix Hermes Bytecode Symbolication one line off ([#3283](https://github.com/getsentry/sentry-react-native/pull/3283))
89

910
### Dependencies
1011

src/js/integrations/rewriteframes.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { RewriteFrames } from '@sentry/integrations';
22
import type { StackFrame } from '@sentry/types';
33
import { Platform } from 'react-native';
44

5-
import { isExpo } from '../utils/environment';
5+
import { isExpo, isHermesEnabled } from '../utils/environment';
66

77
export const ANDROID_DEFAULT_BUNDLE_NAME = 'app:///index.android.bundle';
88
export const IOS_DEFAULT_BUNDLE_NAME = 'app:///main.jsbundle';
@@ -35,6 +35,15 @@ export function createReactNativeRewriteFrames(): RewriteFrames {
3535
if (frame.filename === '[native code]' || frame.filename === 'native') {
3636
return frame;
3737
}
38+
// Is React Native frame
39+
40+
// Check Hermes Bytecode Frame and convert to 1-based column
41+
if (isHermesEnabled() && frame.lineno === 1 && frame.colno !== undefined) {
42+
// hermes bytecode columns are 0-based, while v8 and jsc are 1-based
43+
// Hermes frames without debug info have always line = 1 and col points to a bytecode pos
44+
// https://github.com/facebook/react/issues/21792#issuecomment-873171991
45+
frame.colno += 1;
46+
}
3847

3948
// Expo adds hash to the end of bundle names
4049
if (isExpo() && Platform.OS === 'android') {

test/integrations/rewriteframes.test.ts

+22-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Event } from '@sentry/types';
44
import { Platform } from 'react-native';
55

66
import { createReactNativeRewriteFrames } from '../../src/js/integrations/rewriteframes';
7-
import { isExpo } from '../../src/js/utils/environment';
7+
import { isExpo, isHermesEnabled } from '../../src/js/utils/environment';
88
import { mockFunction } from '../testutils';
99

1010
jest.mock('../../src/js/utils/environment');
@@ -29,6 +29,7 @@ describe('RewriteFrames', () => {
2929

3030
beforeEach(() => {
3131
mockFunction(isExpo).mockReturnValue(false);
32+
mockFunction(isHermesEnabled).mockReturnValue(false);
3233
jest.resetAllMocks();
3334
});
3435

@@ -668,6 +669,8 @@ describe('RewriteFrames', () => {
668669
});
669670

670671
it('should parse React Native errors on Android Hermes', async () => {
672+
mockFunction(isHermesEnabled).mockReturnValue(true);
673+
671674
const ANDROID_REACT_NATIVE_HERMES = {
672675
message: 'Error: lets throw!',
673676
name: 'Error',
@@ -714,28 +717,28 @@ describe('RewriteFrames', () => {
714717
filename: 'app:///index.android.bundle',
715718
function: 'value',
716719
lineno: 1,
717-
colno: 31561,
720+
colno: 31562,
718721
in_app: true,
719722
},
720723
{
721724
filename: 'app:///index.android.bundle',
722725
function: 'value',
723726
lineno: 1,
724-
colno: 32776,
727+
colno: 32777,
725728
in_app: true,
726729
},
727730
{
728731
filename: 'app:///index.android.bundle',
729732
function: 'anonymous',
730733
lineno: 1,
731-
colno: 31603,
734+
colno: 31604,
732735
in_app: true,
733736
},
734737
{
735738
filename: 'app:///index.android.bundle',
736739
function: 'value',
737740
lineno: 1,
738-
colno: 33176,
741+
colno: 33177,
739742
in_app: true,
740743
},
741744
{
@@ -747,42 +750,42 @@ describe('RewriteFrames', () => {
747750
filename: 'app:///index.android.bundle',
748751
function: 'receiveTouches',
749752
lineno: 1,
750-
colno: 122512,
753+
colno: 122513,
751754
in_app: true,
752755
},
753756
{
754757
filename: 'app:///index.android.bundle',
755758
function: 'Ue',
756759
lineno: 1,
757-
colno: 77571,
760+
colno: 77572,
758761
in_app: true,
759762
},
760763
{
761764
filename: 'app:///index.android.bundle',
762765
function: 'Ne',
763766
lineno: 1,
764-
colno: 77238,
767+
colno: 77239,
765768
in_app: true,
766769
},
767770
{
768771
filename: 'app:///index.android.bundle',
769772
function: '_e',
770773
lineno: 1,
771-
colno: 127755,
774+
colno: 127756,
772775
in_app: true,
773776
},
774777
{
775778
filename: 'app:///index.android.bundle',
776779
function: 'anonymous',
777780
lineno: 1,
778-
colno: 77747,
781+
colno: 77748,
779782
in_app: true,
780783
},
781784
{
782785
filename: 'app:///index.android.bundle',
783786
function: 'z',
784787
lineno: 1,
785-
colno: 74642,
788+
colno: 74643,
786789
in_app: true,
787790
},
788791
{
@@ -794,37 +797,37 @@ describe('RewriteFrames', () => {
794797
filename: 'app:///index.android.bundle',
795798
function: 'A',
796799
lineno: 1,
797-
colno: 74709,
800+
colno: 74710,
798801
in_app: true,
799802
},
800803
{
801804
filename: 'app:///index.android.bundle',
802805
function: 'N',
803806
lineno: 1,
804-
colno: 74267,
807+
colno: 74268,
805808
in_app: true,
806809
},
807810
{
808811
filename: 'app:///index.android.bundle',
809812
function: 'C',
810813
lineno: 1,
811-
colno: 74126,
814+
colno: 74127,
812815
in_app: true,
813816
},
814817
{ filename: 'native', function: 'apply', in_app: true },
815818
{
816819
filename: 'app:///index.android.bundle',
817820
function: 'k',
818821
lineno: 1,
819-
colno: 74094,
822+
colno: 74095,
820823
in_app: true,
821824
},
822825
{ filename: 'native', function: 'apply', in_app: true },
823826
{
824827
filename: 'app:///index.android.bundle',
825828
function: 'b',
826829
lineno: 1,
827-
colno: 74037,
830+
colno: 74038,
828831
in_app: true,
829832
},
830833
{ filename: 'native', function: 'apply', in_app: true },
@@ -835,21 +838,21 @@ describe('RewriteFrames', () => {
835838
filename: 'app:///index.android.bundle',
836839
function: '_performSideEffectsForTransition',
837840
lineno: 1,
838-
colno: 230843,
841+
colno: 230844,
839842
in_app: true,
840843
},
841844
{
842845
filename: 'app:///index.android.bundle',
843846
function: 'anonymous',
844847
lineno: 1,
845-
colno: 224280,
848+
colno: 224281,
846849
in_app: true,
847850
},
848851
{
849852
filename: 'app:///index.android.bundle',
850853
function: 'onPress',
851854
lineno: 1,
852-
colno: 452701,
855+
colno: 452702,
853856
in_app: true,
854857
},
855858
],

0 commit comments

Comments
 (0)