@logbrew/react-native 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LogBrewReactNative.podspec +1 -1
- package/README.md +17 -15
- package/android-native-diagnostics.d.ts +15 -5
- package/android-native-diagnostics.js +170 -94
- package/apollo.cjs +435 -226
- package/apollo.d.cts +2 -70
- package/apollo.d.ts +24 -12
- package/apollo.js +438 -221
- package/apple-native-diagnostics-config.js +176 -0
- package/apple-native-diagnostics-context.js +232 -0
- package/apple-native-diagnostics-module.js +229 -0
- package/apple-native-diagnostics.d.ts +42 -11
- package/apple-native-diagnostics.js +60 -389
- package/expo.cjs +29 -16
- package/expo.d.ts +10 -9
- package/expo.js +4 -3
- package/fatal-admission.cjs +113 -0
- package/fatal-record.cjs +317 -0
- package/fatal-replay.cjs +297 -508
- package/global-errors-capture.cjs +369 -0
- package/global-errors-event.cjs +174 -0
- package/global-errors-support.cjs +128 -0
- package/global-errors.cjs +75 -351
- package/global-errors.d.cts +29 -278
- package/global-errors.d.ts +57 -27
- package/global-errors.js +7 -2
- package/global-errors.native.js +83 -48
- package/index-breadcrumbs.cjs +139 -0
- package/index-errors.cjs +167 -0
- package/index-events.cjs +365 -0
- package/index-navigation.cjs +327 -0
- package/index-random.cjs +120 -0
- package/index-react.cjs +189 -0
- package/index-spans.cjs +190 -0
- package/index-trace-fetch.cjs +322 -0
- package/index-trace.cjs +335 -0
- package/index-transport.cjs +201 -0
- package/index-values.cjs +232 -0
- package/index.cjs +95 -1220
- package/index.d.cts +2 -505
- package/index.d.ts +130 -469
- package/index.native.d.ts +146 -22
- package/index.native.js +184 -159
- package/instrumentation-fetch.cjs +113 -0
- package/instrumentation-install.cjs +241 -0
- package/instrumentation-runtime.cjs +65 -0
- package/instrumentation-teardown.cjs +93 -0
- package/instrumentation-values.cjs +282 -0
- package/instrumentation-xhr-request.cjs +298 -0
- package/instrumentation-xhr.cjs +233 -0
- package/instrumentation.cjs +110 -599
- package/instrumentation.d.cts +2 -84
- package/instrumentation.d.ts +22 -8
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
- package/lifecycle.cjs +181 -78
- package/lifecycle.d.cts +1 -50
- package/lifecycle.d.ts +17 -6
- package/metadata.cjs +279 -114
- package/metro-debug-id.cjs +296 -0
- package/metro-serializer.cjs +219 -0
- package/metro.cjs +153 -297
- package/metro.d.cts +2 -57
- package/metro.d.ts +27 -13
- package/metro.js +2 -3
- package/native-bridge-async.cjs +165 -0
- package/native-bridge-scope.cjs +148 -0
- package/native-bridge.cjs +83 -186
- package/native-bridge.d.cts +2 -94
- package/native-bridge.d.ts +28 -15
- package/native-client-bindings.js +230 -0
- package/native-diagnostics-values.js +120 -0
- package/native-module-lookup.js +31 -0
- package/native-null.js +3 -0
- package/null-value.cjs +4 -0
- package/package.json +44 -2
- package/persistent-delivery-store.js +247 -0
- package/persistent-delivery.native.js +183 -261
- package/promise-rejection-handlers.cjs +368 -0
- package/promise-rejections.cjs +169 -361
- package/react-native.config.js +3 -1
- package/release-artifacts-files.cjs +94 -0
- package/release-artifacts-options.cjs +182 -0
- package/release-artifacts.cjs +278 -207
- package/release-artifacts.d.cts +2 -55
- package/release-artifacts.d.ts +18 -7
- package/release-artifacts.js +2 -4
- package/resource-fetch-graphql.cjs +265 -0
- package/resource-fetch-size.cjs +156 -0
- package/resource-fetch.cjs +227 -428
- package/resource-fetch.d.cts +1 -60
- package/resource-fetch.d.ts +17 -6
- package/scripts/sync-apple-native-sources.mjs +101 -53
- package/types/capture.d.ts +95 -0
- package/types/config.d.ts +85 -0
- package/types/defaults.d.ts +55 -0
- package/types/events.d.ts +203 -0
- package/types/provider.d.ts +81 -0
- package/types/trace.d.ts +104 -0
package/global-errors.cjs
CHANGED
|
@@ -1,380 +1,104 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const {
|
|
3
|
+
const { createFatalController } = require("./fatal-replay.cjs");
|
|
4
|
+
const { GlobalErrorCapture, activeInstallation, inactiveInstallation } = require("./global-errors-capture.cjs");
|
|
5
|
+
const { createAutomaticErrorEvent, isSafeErrorName } = require("./global-errors-event.cjs");
|
|
6
|
+
const { DiagnosticGate, emitDiagnostic, isFunction, isObjectLike, safeFunction } = require("./global-errors-support.cjs");
|
|
5
7
|
const {
|
|
6
8
|
createLogBrewReactNativePromiseRejectionHandlers,
|
|
7
9
|
installLogBrewReactNativePromiseRejectionTracker
|
|
8
10
|
} = require("./promise-rejections.cjs");
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function installLogBrewReactNativeGlobalErrorHandler({
|
|
26
|
-
client,
|
|
27
|
-
errorUtils = globalThis?.ErrorUtils,
|
|
28
|
-
fatalStore,
|
|
29
|
-
onDiagnostic
|
|
30
|
-
} = {}) {
|
|
31
|
-
const issue = safeFunction(client, "issue");
|
|
32
|
-
const getGlobalHandler = safeFunction(errorUtils, "getGlobalHandler");
|
|
33
|
-
const setGlobalHandler = safeFunction(errorUtils, "setGlobalHandler");
|
|
34
|
-
if (!issue || !getGlobalHandler || !setGlobalHandler || !isObjectLike(errorUtils)) {
|
|
35
|
-
emitDiagnostic(onDiagnostic, "handler_unavailable");
|
|
36
|
-
return inactiveInstallation();
|
|
37
|
-
}
|
|
12
|
+
/**
|
|
13
|
+
* @import { UnknownFunction } from "./global-errors-support.cjs"
|
|
14
|
+
* @import { LogBrewReactNativeGlobalErrorHandlerInstallation } from "./global-errors.cjs"
|
|
15
|
+
* @typedef {Readonly<{
|
|
16
|
+
* client: object,
|
|
17
|
+
* errorUtils: object,
|
|
18
|
+
* fatalStore: unknown,
|
|
19
|
+
* getGlobalHandler: UnknownFunction,
|
|
20
|
+
* issue: UnknownFunction,
|
|
21
|
+
* onDiagnostic: unknown,
|
|
22
|
+
* previousHandler: UnknownFunction,
|
|
23
|
+
* setGlobalHandler: UnknownFunction
|
|
24
|
+
* }>} InstallationInput
|
|
25
|
+
* @typedef {Readonly<{ client?: unknown, errorUtils?: unknown, fatalStore?: unknown, onDiagnostic?: unknown }>} InstallOptions
|
|
26
|
+
*/
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
if (existing?.health().active) {
|
|
41
|
-
return existing;
|
|
42
|
-
}
|
|
28
|
+
const AUTOMATIC_ERROR_MESSAGE = "React Native global JavaScript report";
|
|
43
29
|
|
|
44
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @param {UnknownFunction} getGlobalHandler
|
|
32
|
+
* @param {object} errorUtils
|
|
33
|
+
* @returns {UnknownFunction | undefined}
|
|
34
|
+
*/
|
|
35
|
+
function readPreviousHandler(getGlobalHandler, errorUtils) {
|
|
45
36
|
try {
|
|
46
|
-
previousHandler = getGlobalHandler.call(errorUtils);
|
|
37
|
+
const previousHandler = getGlobalHandler.call(errorUtils);
|
|
38
|
+
return isFunction(previousHandler) ? previousHandler : undefined;
|
|
47
39
|
} catch {
|
|
48
|
-
|
|
49
|
-
return inactiveInstallation();
|
|
50
|
-
}
|
|
51
|
-
if (typeof previousHandler !== "function") {
|
|
52
|
-
emitDiagnostic(onDiagnostic, "handler_unavailable");
|
|
53
|
-
return inactiveInstallation();
|
|
40
|
+
return undefined;
|
|
54
41
|
}
|
|
42
|
+
}
|
|
55
43
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
44
|
+
/**
|
|
45
|
+
* @param {InstallationInput} input
|
|
46
|
+
* @returns {LogBrewReactNativeGlobalErrorHandlerInstallation}
|
|
47
|
+
*/
|
|
48
|
+
function startCapture(input) {
|
|
49
|
+
const { client, fatalStore, issue, onDiagnostic } = input;
|
|
50
|
+
const diagnostics = new DiagnosticGate(onDiagnostic);
|
|
51
|
+
/**
|
|
52
|
+
* @param {Readonly<{ code: string }>} diagnostic
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
function forwardDiagnostic(diagnostic) {
|
|
56
|
+
diagnostics.emit(diagnostic.code);
|
|
57
|
+
}
|
|
64
58
|
const fatal = createFatalController({
|
|
65
59
|
client,
|
|
66
60
|
createEvent: (error) => createAutomaticErrorEvent(error, client, true),
|
|
67
61
|
eventMessage: AUTOMATIC_ERROR_MESSAGE,
|
|
68
62
|
fatalStore,
|
|
69
|
-
isErrorName:
|
|
63
|
+
isErrorName: isSafeErrorName,
|
|
70
64
|
issue,
|
|
71
|
-
onDiagnostic:
|
|
72
|
-
});
|
|
73
|
-
const capturedErrors = new WeakSet();
|
|
74
|
-
const handler = (error, isFatal) => {
|
|
75
|
-
if (!state.active) {
|
|
76
|
-
previousHandler(error, isFatal);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (state.handling) {
|
|
80
|
-
recordSuppression(state, onDiagnostic, "recursive_capture_suppressed");
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
state.handling = true;
|
|
84
|
-
try {
|
|
85
|
-
if (isFatal === true) {
|
|
86
|
-
if (fatal.available) {
|
|
87
|
-
if (fatal.store(error)) {
|
|
88
|
-
state.lastOutcome = "fatal_stored";
|
|
89
|
-
markPersistedFatal(client);
|
|
90
|
-
} else {
|
|
91
|
-
state.lastOutcome = fatal.health().lastOutcome === "admission_unavailable"
|
|
92
|
-
? "admission_unavailable"
|
|
93
|
-
: "fatal_store_failed";
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
state.lastOutcome = "fatal_unsupported";
|
|
97
|
-
emitStateDiagnostic(state, onDiagnostic, "fatal_capture_requires_sync_store");
|
|
98
|
-
}
|
|
99
|
-
} else if (isObjectLike(error) && capturedErrors.has(error)) {
|
|
100
|
-
recordSuppression(state, onDiagnostic, "duplicate_capture_suppressed");
|
|
101
|
-
} else {
|
|
102
|
-
captureNonfatalError(client, issue, error, capturedErrors, state, onDiagnostic);
|
|
103
|
-
}
|
|
104
|
-
} finally {
|
|
105
|
-
try {
|
|
106
|
-
if (typeof previousHandler === "function") {
|
|
107
|
-
previousHandler(error, isFatal);
|
|
108
|
-
}
|
|
109
|
-
} finally {
|
|
110
|
-
state.handling = false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const installation = Object.freeze({
|
|
116
|
-
discardPendingFatalRecord() {
|
|
117
|
-
return fatal.discard();
|
|
118
|
-
},
|
|
119
|
-
fatalHealth() {
|
|
120
|
-
return fatal.health();
|
|
121
|
-
},
|
|
122
|
-
health() {
|
|
123
|
-
return healthSnapshot(state);
|
|
124
|
-
},
|
|
125
|
-
remove() {
|
|
126
|
-
if (!state.active) {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
let ownsHandler;
|
|
130
|
-
try {
|
|
131
|
-
ownsHandler = getGlobalHandler.call(errorUtils) === handler;
|
|
132
|
-
} catch {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
if (!ownsHandler) {
|
|
136
|
-
state.active = false;
|
|
137
|
-
state.lastOutcome = "handler_replaced";
|
|
138
|
-
installations.delete(errorUtils);
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
setGlobalHandler.call(errorUtils, previousHandler);
|
|
143
|
-
} catch {
|
|
144
|
-
state.lastOutcome = "remove_failed";
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
state.active = false;
|
|
148
|
-
state.lastOutcome = "removed";
|
|
149
|
-
installations.delete(errorUtils);
|
|
150
|
-
return true;
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
try {
|
|
155
|
-
setGlobalHandler.call(errorUtils, handler);
|
|
156
|
-
} catch {
|
|
157
|
-
state.active = false;
|
|
158
|
-
try {
|
|
159
|
-
if (getGlobalHandler.call(errorUtils) === handler) {
|
|
160
|
-
setGlobalHandler.call(errorUtils, previousHandler);
|
|
161
|
-
}
|
|
162
|
-
} catch {
|
|
163
|
-
// An inactive wrapper only delegates if a platform setter failed after mutation.
|
|
164
|
-
}
|
|
165
|
-
emitDiagnostic(onDiagnostic, "handler_unavailable");
|
|
166
|
-
return inactiveInstallation();
|
|
167
|
-
}
|
|
168
|
-
installations.set(errorUtils, installation);
|
|
169
|
-
fatal.replay();
|
|
170
|
-
return installation;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// The last breadcrumb tells Apple crash capture that the JavaScript report already
|
|
174
|
-
// holds this crash, so the RCTFatalException that React Native raises next is not
|
|
175
|
-
// reported twice.
|
|
176
|
-
function markPersistedFatal(client) {
|
|
177
|
-
try {
|
|
178
|
-
client.addBreadcrumb({ category: "react-native.fatal", level: "fatal", type: "error" });
|
|
179
|
-
} catch {
|
|
180
|
-
// The report is stored; without the marker the native copy is only a duplicate.
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function captureNonfatalError(client, issue, error, capturedErrors, state, onDiagnostic) {
|
|
185
|
-
const tracksIdentity = isObjectLike(error);
|
|
186
|
-
if (tracksIdentity) {
|
|
187
|
-
capturedErrors.add(error);
|
|
188
|
-
}
|
|
189
|
-
try {
|
|
190
|
-
const event = createAutomaticErrorEvent(error, client);
|
|
191
|
-
const admission = captureIssueWithAdmission(client, issue, event.id, event.timestamp, event.attributes);
|
|
192
|
-
if (admission !== "admitted") {
|
|
193
|
-
if (tracksIdentity) {
|
|
194
|
-
capturedErrors.delete(error);
|
|
195
|
-
}
|
|
196
|
-
state.lastOutcome = admission === "unavailable"
|
|
197
|
-
? "admission_unavailable"
|
|
198
|
-
: admission === "filtered" ? "filtered" : "capture_failed";
|
|
199
|
-
emitStateDiagnostic(state, onDiagnostic, admission === "unavailable"
|
|
200
|
-
? "capture_admission_unavailable"
|
|
201
|
-
: admission === "filtered" ? "capture_filtered" : "capture_failed");
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
state.capturedEvents = incrementBounded(state.capturedEvents);
|
|
205
|
-
state.lastOutcome = "captured";
|
|
206
|
-
} catch {
|
|
207
|
-
if (tracksIdentity) {
|
|
208
|
-
capturedErrors.delete(error);
|
|
209
|
-
}
|
|
210
|
-
state.lastOutcome = "capture_failed";
|
|
211
|
-
emitStateDiagnostic(state, onDiagnostic, "capture_failed");
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function createAutomaticErrorEvent(error, client, fatal = false) {
|
|
216
|
-
const sanitizedError = new Error(AUTOMATIC_ERROR_MESSAGE);
|
|
217
|
-
sanitizedError.name = safeErrorName(error);
|
|
218
|
-
sanitizedError.stack = automaticStack(error);
|
|
219
|
-
const lastRoute = safeReadProperty(client, LAST_ROUTE);
|
|
220
|
-
const event = createReactNativeErrorEvent(sanitizedError, {
|
|
221
|
-
id: nextEventId(fatal ? "fatal" : "global"),
|
|
222
|
-
handled: false,
|
|
223
|
-
includeStack: false,
|
|
224
|
-
level: fatal ? "fatal" : "error",
|
|
225
|
-
mechanism: "react_native_error_utils"
|
|
65
|
+
onDiagnostic: forwardDiagnostic
|
|
226
66
|
});
|
|
227
|
-
|
|
228
|
-
// Frames keep file basenames only; Debug IDs were already matched on the full path.
|
|
229
|
-
return {
|
|
230
|
-
...event,
|
|
231
|
-
attributes: {
|
|
232
|
-
...event.attributes,
|
|
233
|
-
exceptionChain: {
|
|
234
|
-
...exceptionChain,
|
|
235
|
-
entries: exceptionChain.entries.map((entry) => ({
|
|
236
|
-
...entry,
|
|
237
|
-
...(entry.stackFrames ? { stackFrames: basenameFrames(entry.stackFrames) } : {})
|
|
238
|
-
}))
|
|
239
|
-
},
|
|
240
|
-
...(stackFrames ? { stackFrames: basenameFrames(stackFrames) } : {}),
|
|
241
|
-
title: AUTOMATIC_ERROR_MESSAGE,
|
|
242
|
-
message: AUTOMATIC_ERROR_MESSAGE,
|
|
243
|
-
metadata: {
|
|
244
|
-
...metadata,
|
|
245
|
-
...(metadata.errorFrameFile ? { errorFrameFile: basename(metadata.errorFrameFile) } : {}),
|
|
246
|
-
...(metadata.releaseArtifactCodeFile
|
|
247
|
-
? { releaseArtifactCodeFile: basename(metadata.releaseArtifactCodeFile) }
|
|
248
|
-
: {}),
|
|
249
|
-
...(typeof metadata.issueGroupingKey === "string"
|
|
250
|
-
? { issueGroupingKey: metadata.issueGroupingKey.replace(/^([^:]+:[^:]+:).*[\\/]/u, "$1") }
|
|
251
|
-
: {}),
|
|
252
|
-
automatic: true,
|
|
253
|
-
fatal,
|
|
254
|
-
handled: !fatal,
|
|
255
|
-
...(typeof lastRoute === "string" ? { lastRoute } : {}),
|
|
256
|
-
mechanism: "react_native_error_utils",
|
|
257
|
-
source: "react-native.global_error"
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// Hermes and V8 put the message before the frames. Keep only frame lines so
|
|
264
|
-
// message text cannot become a frame, even when the message changed later.
|
|
265
|
-
function automaticStack(error) {
|
|
266
|
-
const stack = safeReadProperty(error, "stack");
|
|
267
|
-
if (typeof stack !== "string") {
|
|
268
|
-
return "";
|
|
269
|
-
}
|
|
270
|
-
const lines = stack.slice(0, MAX_STACK_BYTES).split(/\r?\n/u);
|
|
271
|
-
const frames = lines.filter((line) => line.trimStart().startsWith("at "));
|
|
272
|
-
return (frames.length > 0 ? frames : lines).join("\n");
|
|
67
|
+
return new GlobalErrorCapture({ ...input, diagnostics, fatal }).install();
|
|
273
68
|
}
|
|
274
69
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const name = safeReadProperty(error, "name");
|
|
285
|
-
const candidate = typeof name === "string" ? name : "Error";
|
|
286
|
-
return SAFE_ERROR_NAMES.has(candidate) ? candidate : "Error";
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function safeReadProperty(value, property) {
|
|
290
|
-
if (!isObjectLike(value)) {
|
|
291
|
-
return undefined;
|
|
292
|
-
}
|
|
293
|
-
try {
|
|
294
|
-
return value[property];
|
|
295
|
-
} catch {
|
|
296
|
-
return undefined;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
function safeFunction(value, property) {
|
|
301
|
-
const candidate = safeReadProperty(value, property);
|
|
302
|
-
return typeof candidate === "function" ? candidate : undefined;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function nextEventId(kind) {
|
|
306
|
-
nextEventSequence = incrementBounded(nextEventSequence);
|
|
307
|
-
return `evt_rn_${kind}_${Date.now().toString(36)}_${nextEventSequence.toString(36)}`;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function incrementBounded(value) {
|
|
311
|
-
return value >= Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : value + 1;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function recordSuppression(state, onDiagnostic, code) {
|
|
315
|
-
state.suppressedEvents = incrementBounded(state.suppressedEvents);
|
|
316
|
-
state.lastOutcome = code === "recursive_capture_suppressed" ? "recursive_suppressed" : "duplicate_suppressed";
|
|
317
|
-
emitStateDiagnostic(state, onDiagnostic, code);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function emitStateDiagnostic(state, onDiagnostic, code) {
|
|
321
|
-
if (state.emittingDiagnostic) {
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
state.emittingDiagnostic = true;
|
|
325
|
-
try {
|
|
326
|
-
emitDiagnostic(onDiagnostic, code);
|
|
327
|
-
} finally {
|
|
328
|
-
state.emittingDiagnostic = false;
|
|
70
|
+
/**
|
|
71
|
+
* @param {Omit<InstallationInput, "previousHandler">} input
|
|
72
|
+
* @returns {LogBrewReactNativeGlobalErrorHandlerInstallation}
|
|
73
|
+
*/
|
|
74
|
+
function installHandler(input) {
|
|
75
|
+
const previousHandler = readPreviousHandler(input.getGlobalHandler, input.errorUtils);
|
|
76
|
+
if (!previousHandler) {
|
|
77
|
+
emitDiagnostic(input.onDiagnostic, "handler_unavailable");
|
|
78
|
+
return inactiveInstallation();
|
|
329
79
|
}
|
|
80
|
+
return startCapture({ ...input, previousHandler });
|
|
330
81
|
}
|
|
331
82
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
83
|
+
/**
|
|
84
|
+
* @param {InstallOptions} [options]
|
|
85
|
+
* @returns {LogBrewReactNativeGlobalErrorHandlerInstallation}
|
|
86
|
+
*/
|
|
87
|
+
function installLogBrewReactNativeGlobalErrorHandler({
|
|
88
|
+
client,
|
|
89
|
+
errorUtils = Reflect.get(globalThis, "ErrorUtils"),
|
|
90
|
+
fatalStore,
|
|
91
|
+
onDiagnostic
|
|
92
|
+
} = {}) {
|
|
93
|
+
const issue = safeFunction(client, "issue");
|
|
94
|
+
const getGlobalHandler = safeFunction(errorUtils, "getGlobalHandler");
|
|
95
|
+
const setGlobalHandler = safeFunction(errorUtils, "setGlobalHandler");
|
|
96
|
+
if (!issue || !getGlobalHandler || !setGlobalHandler || !isObjectLike(errorUtils) || !isObjectLike(client)) {
|
|
97
|
+
emitDiagnostic(onDiagnostic, "handler_unavailable");
|
|
98
|
+
return inactiveInstallation();
|
|
340
99
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
function inactiveInstallation() {
|
|
344
|
-
const snapshot = Object.freeze({
|
|
345
|
-
active: false,
|
|
346
|
-
capturedEvents: 0,
|
|
347
|
-
lastOutcome: "unavailable",
|
|
348
|
-
suppressedEvents: 0
|
|
349
|
-
});
|
|
350
|
-
const fatalSnapshot = Object.freeze({
|
|
351
|
-
acknowledgedRecords: 0,
|
|
352
|
-
available: false,
|
|
353
|
-
corruptRecords: 0,
|
|
354
|
-
droppedRecords: 0,
|
|
355
|
-
lastOutcome: "unavailable",
|
|
356
|
-
replayedRecords: 0,
|
|
357
|
-
storedRecords: 0
|
|
358
|
-
});
|
|
359
|
-
return Object.freeze({
|
|
360
|
-
discardPendingFatalRecord: () => false,
|
|
361
|
-
fatalHealth: () => fatalSnapshot,
|
|
362
|
-
health: () => snapshot,
|
|
363
|
-
remove: () => false
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
function healthSnapshot(state) {
|
|
368
|
-
return Object.freeze({
|
|
369
|
-
active: state.active,
|
|
370
|
-
capturedEvents: state.capturedEvents,
|
|
371
|
-
lastOutcome: state.lastOutcome,
|
|
372
|
-
suppressedEvents: state.suppressedEvents
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
function isObjectLike(value) {
|
|
377
|
-
return value !== null && (typeof value === "object" || typeof value === "function");
|
|
100
|
+
return activeInstallation(errorUtils)
|
|
101
|
+
?? installHandler({ client, errorUtils, fatalStore, getGlobalHandler, issue, onDiagnostic, setGlobalHandler });
|
|
378
102
|
}
|
|
379
103
|
|
|
380
104
|
const defaultExport = {
|