-
-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathErrorsScreen.tsx
More file actions
373 lines (357 loc) · 10.3 KB
/
ErrorsScreen.tsx
File metadata and controls
373 lines (357 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import React, { useEffect } from 'react';
import {
ButtonProps,
Button as NativeButton,
NativeModules,
Platform,
ScrollView,
StatusBar,
StyleSheet,
Text,
View,
} from 'react-native';
import { StackNavigationProp } from '@react-navigation/stack';
import { FallbackRender } from '@sentry/react';
import * as Sentry from '@sentry/react-native';
import NativePlatformSampleModule from '../../tm/NativePlatformSampleModule';
import NativeSampleModule from '../../tm/NativeSampleModule';
import { UserFeedbackModal } from '../components/UserFeedbackModal';
import { setScopeProperties } from '../setScopeProperties';
import { TimeToFullDisplay } from '../utils';
import type { Event as SentryEvent } from '@sentry/core';
const { AssetsModule, CppModule, CrashModule } = NativeModules;
interface Props {
navigation: StackNavigationProp<any, 'HomeScreen'>;
}
const ErrorsScreen = (_props: Props) => {
// Show bad code inside error boundary to trigger it.
const [showBadCode, setShowBadCode] = React.useState(false);
const [isFeedbackVisible, setFeedbackVisible] = React.useState(false);
const [isFeedbackButtonVisible, setFeedbackButtonVisible] =
React.useState(false);
const errorBoundaryFallback: FallbackRender = ({ eventId }) => (
<Text>Error boundary caught with event id: {eventId}</Text>
);
const [data, setData] = React.useState<Uint8Array | null>(null);
useEffect(() => {
AssetsModule?.getExampleAssetData().then((asset: number[]) =>
setData(new Uint8Array(asset)),
);
}, []);
return (
<>
<StatusBar barStyle="dark-content" />
<ScrollView style={styles.mainView}>
<TimeToFullDisplay record={true} />
<Button
title="Capture message"
onPress={() => {
Sentry.captureMessage('Captured message');
}}
/>
<Button
title="Capture exception"
onPress={() => {
Sentry.captureException(new Error('Captured exception'));
}}
/>
<Button
title="Capture exception with cause"
onPress={() => {
const error = new Error('Captured exception');
(error as { cause?: unknown }).cause = new Error(
'Cause of captured exception',
);
Sentry.captureException(error);
}}
/>
<Button
title="Capture exception with breadcrumb"
onPress={() => {
Sentry.captureException(
new Error('Captured exception with breadcrumb'),
context =>
context.addBreadcrumb({ message: 'error with breadcrumb' }),
);
}}
/>
<Button
title="Uncaught Thrown Error"
onPress={() => {
throw new Error('Uncaught Thrown Error');
}}
/>
<Button
title="Unhandled Promise Rejection"
onPress={() => {
Promise.reject('Unhandled Promise Rejection');
}}
/>
<Button
title="Native Crash"
onPress={() => {
Sentry.nativeCrash();
}}
/>
<Button
title="Get Crashed Last Run"
onPress={async () => {
const crashed = await Sentry.crashedLastRun();
console.log('Crashed last run:', crashed);
}}
/>
<Button
title="Set Scope Properties"
onPress={() => {
setScopeProperties();
}}
/>
<Button
title="Send count metric"
onPress={() => {
Sentry.metrics.count('count_metric', 1);
}}
/>
<Button
title="Send distribution metric"
onPress={() => {
Sentry.metrics.count('distribution_metric', 100);
}}
/>
<Button
title="Send count metric with attributes"
onPress={() => {
Sentry.metrics.count('count_metric', 100, { attributes: { from_test_app: true } });
}}
/>
<Button
title="Flush"
onPress={async () => {
await Sentry.flush();
console.log('Sentry.flush() completed.');
}}
/>
<Button
title="Close"
onPress={async () => {
await Sentry.close();
console.log('Sentry.close() completed.');
}}
/>
<Button
title="console.warn()"
onPress={() => {
console.warn('This is a warning.');
}}
/>
<Button
title="Crash in Cpp"
onPress={() => {
NativeSampleModule?.crash();
}}
/>
<Button
title="Catch Turbo Crash or String"
onPress={() => {
if (!NativePlatformSampleModule) {
throw new Error(
'NativePlatformSampleModule is not available. Build the application with the New Architecture enabled.',
);
}
try {
NativePlatformSampleModule?.crashOrString();
} catch (e) {
Sentry.captureException(e);
}
}}
/>
<Button
title="Log console"
onPress={() => {
Sentry.logger.info('info log');
Sentry.logger.trace('trace log');
Sentry.logger.debug('debug log');
Sentry.logger.warn('warn log');
Sentry.logger.error('error log');
Sentry.logger.info('info log with data', { database: 'admin', number: 123, obj: { password: 'admin' } });
}}
/>
{Platform.OS === 'android' && (
<>
<Button
title="Crash in Android Cpp"
onPress={() => {
CppModule?.crashCpp();
}}
/>
<Button
title="JVM Crash or Undefined"
onPress={() => {
CrashModule.crashOrUndefined();
}}
/>
<Button
title="JVM Crash or Number"
onPress={() => {
CrashModule.crashOrNumber().then((n: number) => {
console.log('Got number: ' + n);
});
}}
/>
</>
)}
<Spacer />
<Sentry.ErrorBoundary fallback={errorBoundaryFallback}>
<Button
title="Activate Error Boundary"
onPress={() => {
setShowBadCode(true);
}}
/>
{showBadCode && <div />}
</Sentry.ErrorBoundary>
<Spacer />
<Button
title="Add attachment"
onPress={() => {
const scope = Sentry.getGlobalScope();
scope.addAttachment({
data: 'Attachment content',
filename: 'attachment.txt',
contentType: 'text/plain',
});
if (data) {
scope.addAttachment({
data,
filename: 'logo.png',
contentType: 'image/png',
});
}
console.log('Sentry attachment added.');
}}
/>
<Button
title="Capture HTTP Client Error"
onPress={async () => {
try {
fetch('http://localhost:8081/not-found');
} catch (error) {
//ignore the error, it will be send to Sentry automatically
}
}}
/>
<Button
title="Set different types of tags globally"
onPress={async () => {
Sentry.setTags({
number: 123,
boolean: true,
null: null,
undefined: undefined,
symbol: Symbol('symbol'),
string: 'string',
bigint: BigInt(123),
});
Sentry.captureMessage('Message with different types of tags globally');
Sentry.setTags({
number: undefined,
boolean: undefined,
null: undefined,
symbol: undefined,
string: undefined,
bigint: undefined,
});
}}
/>
<Button
title="Set different types of tags in scope"
onPress={async () => {
const evt: SentryEvent = {
message: 'Message with different types of tags isolated',
tags: {
number: 123,
boolean: true,
null: null,
undefined: undefined,
symbol: Symbol('symbol'),
string: 'abc',
bigint: BigInt(123),
},
};
Sentry.captureEvent(evt);
}}
/>
<Button
title="Feedback form"
onPress={() => {
_props.navigation.navigate('FeedbackWidget');
}}
/>
<Button
title="Feedback form (auto)"
onPress={() => {
Sentry.showFeedbackWidget();
}}
/>
<Button
title="Show/Hide Feedback Button"
onPress={() => {
if (isFeedbackButtonVisible) {
Sentry.hideFeedbackButton();
setFeedbackButtonVisible(false);
} else {
Sentry.showFeedbackButton();
setFeedbackButtonVisible(true);
}
}}
/>
<Button
title="Send user feedback"
onPress={() => {
setFeedbackVisible(true);
}}
/>
{isFeedbackVisible ? (
<UserFeedbackModal
onDismiss={() => {
setFeedbackVisible(false);
}}
/>
) : null}
<View style={styles.mainViewBottomWhiteSpace} />
</ScrollView>
</>
);
};
const Button = (props: ButtonProps) => (
<>
<NativeButton {...props} color="#6C5FC7" />
<View style={styles.buttonSpacer} />
</>
);
const Spacer = () => <View style={styles.spacer} />;
const styles = StyleSheet.create({
welcomeTitle: {
fontSize: 24,
fontWeight: '600',
color: '#362D59',
marginBottom: 20,
},
buttonSpacer: {
marginBottom: 8,
},
spacer: {
height: 1,
width: '100%',
backgroundColor: '#c6becf',
marginBottom: 16,
marginTop: 8,
},
mainView: {
padding: 20,
},
mainViewBottomWhiteSpace: {
marginTop: 32,
},
});
export default ErrorsScreen;