@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/fatal-replay.cjs
CHANGED
|
@@ -1,331 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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
|
-
discard() {
|
|
37
|
-
return discardPendingFatal(fatalStore, methods, state, onDiagnostic);
|
|
38
|
-
},
|
|
39
|
-
health() {
|
|
40
|
-
return fatalHealthSnapshot(state);
|
|
41
|
-
},
|
|
42
|
-
replay() {
|
|
43
|
-
if (!methods) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
replayPendingFatal({
|
|
47
|
-
client,
|
|
48
|
-
eventMessage,
|
|
49
|
-
fatalStore,
|
|
50
|
-
isErrorName,
|
|
51
|
-
issue,
|
|
52
|
-
methods,
|
|
53
|
-
onDiagnostic,
|
|
54
|
-
state
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
store(error) {
|
|
58
|
-
if (!methods) {
|
|
59
|
-
return directAdmission
|
|
60
|
-
? admitFatalError({ client, createEvent, error, issue, onDiagnostic, state })
|
|
61
|
-
: false;
|
|
62
|
-
}
|
|
63
|
-
return storeFatalError({
|
|
64
|
-
createEvent,
|
|
65
|
-
error,
|
|
66
|
-
fatalStore,
|
|
67
|
-
methods,
|
|
68
|
-
onDiagnostic,
|
|
69
|
-
state
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function admitFatalError({ client, createEvent, error, issue, onDiagnostic, state }) {
|
|
76
|
-
let admission;
|
|
77
|
-
try {
|
|
78
|
-
const event = createEvent(error);
|
|
79
|
-
admission = captureIssueWithAdmission(client, issue, event.id, event.timestamp, event.attributes);
|
|
80
|
-
} catch {
|
|
81
|
-
state.lastOutcome = "storage_error";
|
|
82
|
-
emitDiagnostic(onDiagnostic, "fatal_store_failed");
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
if (admission === "unavailable") {
|
|
86
|
-
state.lastOutcome = "admission_unavailable";
|
|
87
|
-
emitDiagnostic(onDiagnostic, "fatal_admission_unavailable");
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
if (admission !== "admitted") {
|
|
91
|
-
state.lastOutcome = "storage_error";
|
|
92
|
-
emitDiagnostic(onDiagnostic, "fatal_store_failed");
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
state.storedRecords = incrementBounded(state.storedRecords);
|
|
96
|
-
state.lastOutcome = "stored";
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function fatalStoreMethods(fatalStore) {
|
|
101
|
-
if (!isObjectLike(fatalStore)) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
const methods = {
|
|
105
|
-
acknowledge: safeFunction(fatalStore, "acknowledgeFatalRecord"),
|
|
106
|
-
discard: safeFunction(fatalStore, "discardFatalRecord"),
|
|
107
|
-
read: safeFunction(fatalStore, "readFatalRecord"),
|
|
108
|
-
write: safeFunction(fatalStore, "writeFatalRecord")
|
|
109
|
-
};
|
|
110
|
-
return Object.values(methods).every((method) => typeof method === "function")
|
|
111
|
-
? methods
|
|
112
|
-
: undefined;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function discardPendingFatal(fatalStore, methods, state, onDiagnostic) {
|
|
116
|
-
if (!methods) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
let result;
|
|
120
|
-
try {
|
|
121
|
-
result = methods.discard.call(fatalStore);
|
|
122
|
-
} catch {
|
|
123
|
-
state.lastOutcome = "discard_failed";
|
|
124
|
-
emitDiagnostic(onDiagnostic, "fatal_discard_failed");
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
if (resultStatus(result) !== "discarded") {
|
|
128
|
-
state.lastOutcome = resultStatus(result) === "empty" ? "empty" : "discard_failed";
|
|
129
|
-
if (state.lastOutcome === "discard_failed") {
|
|
130
|
-
emitDiagnostic(onDiagnostic, "fatal_discard_failed");
|
|
131
|
-
}
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
state.lastOutcome = "discarded";
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function storeFatalError({
|
|
139
|
-
createEvent,
|
|
140
|
-
error,
|
|
141
|
-
fatalStore,
|
|
142
|
-
methods,
|
|
143
|
-
onDiagnostic,
|
|
144
|
-
state
|
|
145
|
-
}) {
|
|
146
|
-
if (!methods) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
let result;
|
|
150
|
-
try {
|
|
151
|
-
result = methods.write.call(fatalStore, createFatalRecord(createEvent(error)));
|
|
152
|
-
} catch {
|
|
153
|
-
result = undefined;
|
|
154
|
-
}
|
|
155
|
-
const status = resultStatus(result);
|
|
156
|
-
if (status === "stored" || status === "stored_after_corruption") {
|
|
157
|
-
state.storedRecords = incrementBounded(state.storedRecords);
|
|
158
|
-
state.corruptRecords = boundedResultCounter(result, "corruptRecords", state.corruptRecords);
|
|
159
|
-
state.lastOutcome = status;
|
|
160
|
-
return true;
|
|
161
|
-
}
|
|
162
|
-
if (status === "dropped_pending") {
|
|
163
|
-
state.droppedRecords = boundedResultCounter(
|
|
164
|
-
result,
|
|
165
|
-
"droppedRecords",
|
|
166
|
-
incrementBounded(state.droppedRecords)
|
|
167
|
-
);
|
|
168
|
-
state.lastOutcome = status;
|
|
169
|
-
emitDiagnostic(onDiagnostic, "fatal_record_dropped");
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
state.lastOutcome = "storage_error";
|
|
173
|
-
emitDiagnostic(onDiagnostic, "fatal_store_failed");
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function replayPendingFatal({
|
|
178
|
-
client,
|
|
179
|
-
eventMessage,
|
|
180
|
-
fatalStore,
|
|
181
|
-
isErrorName,
|
|
182
|
-
issue,
|
|
183
|
-
methods,
|
|
184
|
-
onDiagnostic,
|
|
185
|
-
state
|
|
186
|
-
}) {
|
|
187
|
-
if (!methods) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
let result;
|
|
191
|
-
try {
|
|
192
|
-
result = methods.read.call(fatalStore);
|
|
193
|
-
} catch {
|
|
194
|
-
result = undefined;
|
|
195
|
-
}
|
|
196
|
-
const status = resultStatus(result);
|
|
197
|
-
if (status === "empty") {
|
|
198
|
-
state.lastOutcome = "empty";
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
if (status === "corrupt_discarded") {
|
|
202
|
-
state.corruptRecords = boundedResultCounter(
|
|
203
|
-
result,
|
|
204
|
-
"corruptRecords",
|
|
205
|
-
incrementBounded(state.corruptRecords)
|
|
206
|
-
);
|
|
207
|
-
state.lastOutcome = status;
|
|
208
|
-
emitDiagnostic(onDiagnostic, "fatal_corrupt_record_discarded");
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const record = status === "pending"
|
|
212
|
-
? validatedFatalRecord(safeReadProperty(result, "record"), isErrorName)
|
|
213
|
-
: undefined;
|
|
214
|
-
if (!record) {
|
|
215
|
-
state.lastOutcome = "replay_failed";
|
|
216
|
-
emitDiagnostic(onDiagnostic, "fatal_replay_failed");
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
state.corruptRecords = Math.max(state.corruptRecords, record.corruptRecords);
|
|
221
|
-
state.droppedRecords = Math.max(state.droppedRecords, record.droppedRecords);
|
|
222
|
-
if (wasAdmittedInRuntime(client, record.id)) {
|
|
223
|
-
acknowledgeFatalRecord(fatalStore, methods, record.id, state, onDiagnostic);
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
let admission;
|
|
228
|
-
try {
|
|
229
|
-
admission = captureIssueWithAdmission(
|
|
230
|
-
client, issue, record.id, record.timestamp, fatalEventAttributes(record, eventMessage)
|
|
231
|
-
);
|
|
232
|
-
} catch {
|
|
233
|
-
state.lastOutcome = "replay_failed";
|
|
234
|
-
emitDiagnostic(onDiagnostic, "fatal_replay_failed");
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
if (admission === "unavailable") {
|
|
238
|
-
state.lastOutcome = "admission_unavailable";
|
|
239
|
-
emitDiagnostic(onDiagnostic, "fatal_replay_admission_unavailable");
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
if (admission !== "admitted") {
|
|
243
|
-
state.lastOutcome = "replay_not_admitted";
|
|
244
|
-
emitDiagnostic(onDiagnostic, "fatal_replay_not_admitted");
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
rememberAdmittedFatalId(client, record.id);
|
|
249
|
-
state.replayedRecords = incrementBounded(state.replayedRecords);
|
|
250
|
-
acknowledgeFatalRecord(fatalStore, methods, record.id, state, onDiagnostic);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function acknowledgeFatalRecord(fatalStore, methods, recordId, state, onDiagnostic) {
|
|
254
|
-
let result;
|
|
255
|
-
try {
|
|
256
|
-
result = methods.acknowledge.call(fatalStore, recordId);
|
|
257
|
-
} catch {
|
|
258
|
-
result = undefined;
|
|
259
|
-
}
|
|
260
|
-
if (resultStatus(result) === "acknowledged"
|
|
261
|
-
&& safeReadProperty(result, "recordId") === recordId) {
|
|
262
|
-
state.acknowledgedRecords = incrementBounded(state.acknowledgedRecords);
|
|
263
|
-
state.lastOutcome = "acknowledged";
|
|
264
|
-
return;
|
|
265
|
-
}
|
|
266
|
-
state.lastOutcome = "acknowledge_failed";
|
|
267
|
-
emitDiagnostic(onDiagnostic, "fatal_acknowledge_failed");
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function captureIssueWithAdmission(client, issue, id, timestamp, attributes) {
|
|
271
|
-
const capture = safeFunction(client, "issueWithAdmission");
|
|
272
|
-
if (!capture) {
|
|
273
|
-
issue.call(client, id, timestamp, attributes);
|
|
274
|
-
return "unavailable";
|
|
275
|
-
}
|
|
276
|
-
const status = resultStatus(capture.call(client, id, timestamp, attributes));
|
|
277
|
-
return status === "admitted" || status === "filtered" || status === "dropped"
|
|
278
|
-
? status
|
|
279
|
-
: "unavailable";
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function wasAdmittedInRuntime(client, recordId) {
|
|
283
|
-
return isObjectLike(client) && admittedFatalIdsByClient.get(client)?.has(recordId) === true;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function rememberAdmittedFatalId(client, recordId) {
|
|
287
|
-
if (!isObjectLike(client)) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
let admittedIds = admittedFatalIdsByClient.get(client);
|
|
291
|
-
if (!admittedIds) {
|
|
292
|
-
admittedIds = new Set();
|
|
293
|
-
admittedFatalIdsByClient.set(client, admittedIds);
|
|
294
|
-
}
|
|
295
|
-
if (admittedIds.has(recordId)) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
admittedIds.add(recordId);
|
|
299
|
-
if (admittedIds.size > MAX_ADMITTED_FATAL_IDS) {
|
|
300
|
-
admittedIds.delete(admittedIds.values().next().value);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
3
|
+
const { emitDiagnostic, incrementBounded, safeReadProperty } = require("./global-errors-support.cjs");
|
|
4
|
+
const { boundedResultCounter, createFatalRecord, resultStatus, validatedFatalRecord } = require("./fatal-record.cjs");
|
|
5
|
+
const {
|
|
6
|
+
attempt,
|
|
7
|
+
captureIssueWithAdmission,
|
|
8
|
+
fatalStoreMethods,
|
|
9
|
+
rememberAdmittedFatalId,
|
|
10
|
+
wasAdmittedInRuntime
|
|
11
|
+
} = require("./fatal-admission.cjs");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @import { UnknownFunction } from "./global-errors-support.cjs"
|
|
15
|
+
* @import { FatalEventInput, FatalRecord } from "./fatal-record.cjs"
|
|
16
|
+
* @import { ReactNativeFatalReplayHealth } from "./global-errors.cjs"
|
|
17
|
+
* @import { Admission, FatalStoreMethods } from "./fatal-admission.cjs"
|
|
18
|
+
* @typedef {ReactNativeFatalReplayHealth["lastOutcome"]} FatalOutcome
|
|
19
|
+
* @typedef {Readonly<{
|
|
20
|
+
* client: unknown,
|
|
21
|
+
* createEvent: (error: unknown) => FatalEventInput,
|
|
22
|
+
* eventMessage: string,
|
|
23
|
+
* fatalStore: unknown,
|
|
24
|
+
* isErrorName: (value: unknown) => boolean,
|
|
25
|
+
* issue: UnknownFunction,
|
|
26
|
+
* onDiagnostic: unknown
|
|
27
|
+
* }>} FatalControllerOptions
|
|
28
|
+
* @typedef {Readonly<{
|
|
29
|
+
* available: boolean,
|
|
30
|
+
* discard: () => boolean,
|
|
31
|
+
* health: () => ReactNativeFatalReplayHealth,
|
|
32
|
+
* replay: () => void,
|
|
33
|
+
* store: (error: unknown) => boolean
|
|
34
|
+
* }>} FatalController
|
|
35
|
+
*/
|
|
303
36
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
corruptRecords: 0,
|
|
307
|
-
droppedRecords: 0,
|
|
308
|
-
errorName: event.attributes.exception.type,
|
|
309
|
-
id: event.id,
|
|
310
|
-
schemaVersion: FATAL_RECORD_SCHEMA_VERSION,
|
|
311
|
-
stackFrames: (event.attributes.stackFrames ?? []).flatMap(({ column, filename, line }) => {
|
|
312
|
-
const stored = normalizedStoredFatalFilename(filename);
|
|
313
|
-
return validFatalFilename(stored) ? [{ column, filename: stored, line }] : [];
|
|
314
|
-
}).slice(0, MAX_FATAL_STACK_FRAMES),
|
|
315
|
-
timestamp: event.timestamp
|
|
316
|
-
};
|
|
317
|
-
while (record.stackFrames.length > 0 && utf8ByteLength(JSON.stringify(record)) > MAX_FATAL_RECORD_BYTES) {
|
|
318
|
-
record.stackFrames.pop();
|
|
319
|
-
}
|
|
320
|
-
return record;
|
|
321
|
-
}
|
|
37
|
+
const DURABLE_QUEUE = Symbol.for("co.logbrew.react-native.durable-event-queue");
|
|
38
|
+
const NO_COUNT = 0;
|
|
322
39
|
|
|
40
|
+
/**
|
|
41
|
+
* @param {FatalRecord} record
|
|
42
|
+
* @param {string} eventMessage
|
|
43
|
+
* @returns {Readonly<Record<string, unknown>>}
|
|
44
|
+
*/
|
|
323
45
|
function fatalEventAttributes(record, eventMessage) {
|
|
324
46
|
return Object.freeze({
|
|
325
47
|
exception: Object.freeze({
|
|
326
48
|
type: record.errorName,
|
|
49
|
+
|
|
327
50
|
mechanism: Object.freeze({
|
|
328
51
|
type: "react_native_error_utils",
|
|
52
|
+
|
|
329
53
|
handled: false
|
|
330
54
|
})
|
|
331
55
|
}),
|
|
@@ -341,221 +65,286 @@ function fatalEventAttributes(record, eventMessage) {
|
|
|
341
65
|
replayed: true,
|
|
342
66
|
source: "react-native.global_error"
|
|
343
67
|
}),
|
|
344
|
-
...(record.stackFrames.length ===
|
|
68
|
+
...(record.stackFrames.length === NO_COUNT
|
|
345
69
|
? {}
|
|
346
70
|
: { stackFrames: record.stackFrames.map((frame) => Object.freeze({ ...frame })) }),
|
|
347
71
|
title: eventMessage
|
|
348
72
|
});
|
|
349
73
|
}
|
|
350
74
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
stackFrames: frames,
|
|
394
|
-
timestamp
|
|
395
|
-
};
|
|
396
|
-
return utf8ByteLength(JSON.stringify(record)) <= MAX_FATAL_RECORD_BYTES ? record : undefined;
|
|
397
|
-
} catch {
|
|
398
|
-
return undefined;
|
|
75
|
+
class FatalReplay {
|
|
76
|
+
/**
|
|
77
|
+
* @param {FatalControllerOptions} options
|
|
78
|
+
*/
|
|
79
|
+
constructor(options) {
|
|
80
|
+
this.options = options;
|
|
81
|
+
this.methods = fatalStoreMethods(options.fatalStore);
|
|
82
|
+
this.directAdmission = !this.methods && safeReadProperty(options.client, DURABLE_QUEUE) === true;
|
|
83
|
+
this.acknowledgedRecords = NO_COUNT;
|
|
84
|
+
this.available = this.methods !== undefined || this.directAdmission;
|
|
85
|
+
this.corruptRecords = NO_COUNT;
|
|
86
|
+
this.droppedRecords = NO_COUNT;
|
|
87
|
+
/** @type {FatalOutcome} */
|
|
88
|
+
this.lastOutcome = this.methods || this.directAdmission ? "idle" : "unavailable";
|
|
89
|
+
this.replayedRecords = NO_COUNT;
|
|
90
|
+
this.storedRecords = NO_COUNT;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @returns {ReactNativeFatalReplayHealth}
|
|
95
|
+
*/
|
|
96
|
+
health() {
|
|
97
|
+
return Object.freeze({
|
|
98
|
+
acknowledgedRecords: this.acknowledgedRecords,
|
|
99
|
+
available: this.available,
|
|
100
|
+
corruptRecords: this.corruptRecords,
|
|
101
|
+
droppedRecords: this.droppedRecords,
|
|
102
|
+
lastOutcome: this.lastOutcome,
|
|
103
|
+
replayedRecords: this.replayedRecords,
|
|
104
|
+
storedRecords: this.storedRecords
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {FatalOutcome} outcome
|
|
110
|
+
* @param {string} code
|
|
111
|
+
* @returns {false}
|
|
112
|
+
*/
|
|
113
|
+
fail(outcome, code) {
|
|
114
|
+
this.lastOutcome = outcome;
|
|
115
|
+
emitDiagnostic(this.options.onDiagnostic, code);
|
|
116
|
+
return false;
|
|
399
117
|
}
|
|
400
|
-
}
|
|
401
118
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
119
|
+
/**
|
|
120
|
+
* @param {unknown} error
|
|
121
|
+
* @returns {Admission | undefined}
|
|
122
|
+
*/
|
|
123
|
+
admission(error) {
|
|
124
|
+
const { client, createEvent, issue } = this.options;
|
|
125
|
+
try {
|
|
126
|
+
const event = createEvent(error);
|
|
127
|
+
return captureIssueWithAdmission(client, issue, event.id, event.timestamp, event.attributes);
|
|
128
|
+
} catch {
|
|
412
129
|
return undefined;
|
|
413
130
|
}
|
|
414
|
-
return {
|
|
415
|
-
column,
|
|
416
|
-
filename,
|
|
417
|
-
line
|
|
418
|
-
};
|
|
419
|
-
} catch {
|
|
420
|
-
return undefined;
|
|
421
131
|
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function validFatalFilename(value) {
|
|
425
|
-
return typeof value === "string"
|
|
426
|
-
&& value.length > 0
|
|
427
|
-
&& utf8ByteLength(value) <= MAX_FATAL_FILENAME_BYTES
|
|
428
|
-
&& !hasControlCharacter(value)
|
|
429
|
-
&& !value.startsWith("/")
|
|
430
|
-
&& !/^[A-Za-z]:/u.test(value)
|
|
431
|
-
&& !value.includes("\\")
|
|
432
|
-
&& !value.includes("://")
|
|
433
|
-
&& !value.includes("?")
|
|
434
|
-
&& !value.includes("#")
|
|
435
|
-
&& !value.split("/").includes("..");
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function normalizedStoredFatalFilename(value) {
|
|
439
|
-
return typeof value === "string"
|
|
440
|
-
&& value.startsWith("/")
|
|
441
|
-
&& value.length > 1
|
|
442
|
-
&& value.indexOf("/", 1) === -1
|
|
443
|
-
? value.slice(1)
|
|
444
|
-
: value;
|
|
445
|
-
}
|
|
446
132
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
133
|
+
/**
|
|
134
|
+
* @param {unknown} error
|
|
135
|
+
* @returns {boolean}
|
|
136
|
+
*/
|
|
137
|
+
admit(error) {
|
|
138
|
+
const admission = this.admission(error);
|
|
139
|
+
if (admission === "unavailable") {
|
|
140
|
+
return this.fail("admission_unavailable", "fatal_admission_unavailable");
|
|
141
|
+
}
|
|
142
|
+
if (admission !== "admitted") {
|
|
143
|
+
return this.fail("storage_error", "fatal_store_failed");
|
|
144
|
+
}
|
|
145
|
+
this.storedRecords = incrementBounded(this.storedRecords);
|
|
146
|
+
this.lastOutcome = "stored";
|
|
147
|
+
return true;
|
|
460
148
|
}
|
|
461
|
-
}
|
|
462
149
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
return
|
|
472
|
-
&& keys.every((key, index) => key === expected[index]);
|
|
473
|
-
} catch {
|
|
474
|
-
return false;
|
|
150
|
+
/**
|
|
151
|
+
* @returns {boolean}
|
|
152
|
+
*/
|
|
153
|
+
discard() {
|
|
154
|
+
const { methods } = this;
|
|
155
|
+
if (!methods) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return this.recordDiscardResult(attempt(() => methods.discard.call(this.options.fatalStore)));
|
|
475
159
|
}
|
|
476
|
-
}
|
|
477
160
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
161
|
+
/**
|
|
162
|
+
* @param {unknown} result
|
|
163
|
+
* @returns {boolean}
|
|
164
|
+
*/
|
|
165
|
+
recordDiscardResult(result) {
|
|
166
|
+
if (resultStatus(result) === "discarded") {
|
|
167
|
+
this.lastOutcome = "discarded";
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (resultStatus(result) === "empty") {
|
|
171
|
+
this.lastOutcome = "empty";
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
return this.fail("discard_failed", "fatal_discard_failed");
|
|
491
175
|
}
|
|
492
|
-
}
|
|
493
176
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
177
|
+
/**
|
|
178
|
+
* @param {unknown} error
|
|
179
|
+
* @returns {boolean}
|
|
180
|
+
*/
|
|
181
|
+
store(error) {
|
|
182
|
+
const { methods } = this;
|
|
183
|
+
if (!methods) {
|
|
184
|
+
return this.directAdmission ? this.admit(error) : false;
|
|
185
|
+
}
|
|
186
|
+
const { createEvent, fatalStore } = this.options;
|
|
187
|
+
return this.recordStoreResult(attempt(() => methods.write.call(fatalStore, createFatalRecord(createEvent(error)))));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @param {unknown} result
|
|
192
|
+
* @returns {boolean}
|
|
193
|
+
*/
|
|
194
|
+
recordStoreResult(result) {
|
|
195
|
+
const status = resultStatus(result);
|
|
196
|
+
if (status === "stored" || status === "stored_after_corruption") {
|
|
197
|
+
this.storedRecords = incrementBounded(this.storedRecords);
|
|
198
|
+
this.corruptRecords = boundedResultCounter(result, "corruptRecords", this.corruptRecords);
|
|
199
|
+
this.lastOutcome = status;
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (status === "dropped_pending") {
|
|
203
|
+
this.droppedRecords = boundedResultCounter(result, "droppedRecords", incrementBounded(this.droppedRecords));
|
|
204
|
+
return this.fail(status, "fatal_record_dropped");
|
|
205
|
+
}
|
|
206
|
+
return this.fail("storage_error", "fatal_store_failed");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @param {FatalStoreMethods} methods
|
|
211
|
+
* @param {string} recordId
|
|
212
|
+
* @returns {void}
|
|
213
|
+
*/
|
|
214
|
+
acknowledge(methods, recordId) {
|
|
215
|
+
const result = attempt(() => methods.acknowledge.call(this.options.fatalStore, recordId));
|
|
216
|
+
if (resultStatus(result) === "acknowledged"
|
|
217
|
+
&& safeReadProperty(result, "recordId") === recordId) {
|
|
218
|
+
this.acknowledgedRecords = incrementBounded(this.acknowledgedRecords);
|
|
219
|
+
this.lastOutcome = "acknowledged";
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
this.fail("acknowledge_failed", "fatal_acknowledge_failed");
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @param {FatalRecord} record
|
|
227
|
+
* @returns {Admission | undefined}
|
|
228
|
+
*/
|
|
229
|
+
replayAdmission(record) {
|
|
230
|
+
const { client, eventMessage, issue } = this.options;
|
|
231
|
+
try {
|
|
232
|
+
return captureIssueWithAdmission(client, issue, record.id, record.timestamp, fatalEventAttributes(record, eventMessage));
|
|
233
|
+
} catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
502
236
|
}
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
function safeFunction(value, property) {
|
|
506
|
-
const candidate = safeReadProperty(value, property);
|
|
507
|
-
return typeof candidate === "function" ? candidate : undefined;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
function hasControlCharacter(value) {
|
|
511
|
-
return Array.from(value).some((character) => {
|
|
512
|
-
const code = character.codePointAt(0);
|
|
513
|
-
return code !== undefined && (code <= 31 || code === 127);
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
function positiveInteger(value) {
|
|
518
|
-
return Number.isSafeInteger(value) && value > 0 && value <= 2147483647 ? value : undefined;
|
|
519
|
-
}
|
|
520
237
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
238
|
+
/**
|
|
239
|
+
* @param {FatalStoreMethods} methods
|
|
240
|
+
* @param {FatalRecord} record
|
|
241
|
+
* @returns {void}
|
|
242
|
+
*/
|
|
243
|
+
replayRecord(methods, record) {
|
|
244
|
+
this.corruptRecords = Math.max(this.corruptRecords, record.corruptRecords);
|
|
245
|
+
this.droppedRecords = Math.max(this.droppedRecords, record.droppedRecords);
|
|
246
|
+
if (wasAdmittedInRuntime(this.options.client, record.id)) {
|
|
247
|
+
this.acknowledge(methods, record.id);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
this.recordReplayAdmission(methods, record, this.replayAdmission(record));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @param {FatalStoreMethods} methods
|
|
255
|
+
* @param {FatalRecord} record
|
|
256
|
+
* @param {Admission | undefined} admission
|
|
257
|
+
* @returns {void}
|
|
258
|
+
*/
|
|
259
|
+
recordReplayAdmission(methods, record, admission) {
|
|
260
|
+
if (admission === undefined) {
|
|
261
|
+
this.fail("replay_failed", "fatal_replay_failed");
|
|
262
|
+
} else if (admission === "unavailable") {
|
|
263
|
+
this.fail("admission_unavailable", "fatal_replay_admission_unavailable");
|
|
264
|
+
} else if (admission === "admitted") {
|
|
265
|
+
rememberAdmittedFatalId(this.options.client, record.id);
|
|
266
|
+
this.replayedRecords = incrementBounded(this.replayedRecords);
|
|
267
|
+
this.acknowledge(methods, record.id);
|
|
268
|
+
} else {
|
|
269
|
+
this.fail("replay_not_admitted", "fatal_replay_not_admitted");
|
|
270
|
+
}
|
|
533
271
|
}
|
|
534
|
-
}
|
|
535
272
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
273
|
+
/**
|
|
274
|
+
* @returns {void}
|
|
275
|
+
*/
|
|
276
|
+
replay() {
|
|
277
|
+
const { methods } = this;
|
|
278
|
+
if (!methods) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
this.recordReadResult(methods, attempt(() => methods.read.call(this.options.fatalStore)));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @param {FatalStoreMethods} methods
|
|
286
|
+
* @param {unknown} result
|
|
287
|
+
* @returns {void}
|
|
288
|
+
*/
|
|
289
|
+
recordReadResult(methods, result) {
|
|
290
|
+
const status = resultStatus(result);
|
|
291
|
+
if (status === "empty") {
|
|
292
|
+
this.lastOutcome = "empty";
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (status === "corrupt_discarded") {
|
|
296
|
+
this.corruptRecords = boundedResultCounter(result, "corruptRecords", incrementBounded(this.corruptRecords));
|
|
297
|
+
this.fail(status, "fatal_corrupt_record_discarded");
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
this.replayResult(methods, status === "pending"
|
|
301
|
+
? validatedFatalRecord(safeReadProperty(result, "record"), this.options.isErrorName)
|
|
302
|
+
: undefined);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* @param {FatalStoreMethods} methods
|
|
307
|
+
* @param {FatalRecord | undefined} record
|
|
308
|
+
* @returns {void}
|
|
309
|
+
*/
|
|
310
|
+
replayResult(methods, record) {
|
|
311
|
+
if (record) {
|
|
312
|
+
this.replayRecord(methods, record);
|
|
313
|
+
} else {
|
|
314
|
+
this.fail("replay_failed", "fatal_replay_failed");
|
|
315
|
+
}
|
|
541
316
|
}
|
|
542
|
-
return bytes;
|
|
543
317
|
}
|
|
544
318
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
319
|
+
/**
|
|
320
|
+
* @param {FatalControllerOptions} options
|
|
321
|
+
* @returns {FatalController}
|
|
322
|
+
*/
|
|
323
|
+
function createFatalController({
|
|
324
|
+
client,
|
|
325
|
+
createEvent,
|
|
326
|
+
eventMessage,
|
|
327
|
+
fatalStore,
|
|
328
|
+
isErrorName,
|
|
329
|
+
issue,
|
|
330
|
+
onDiagnostic
|
|
331
|
+
}) {
|
|
332
|
+
const fatal = new FatalReplay({ client, createEvent, eventMessage, fatalStore, isErrorName, issue, onDiagnostic });
|
|
333
|
+
return {
|
|
334
|
+
available: fatal.available,
|
|
335
|
+
discard() {
|
|
336
|
+
return fatal.discard();
|
|
337
|
+
},
|
|
338
|
+
health() {
|
|
339
|
+
return fatal.health();
|
|
340
|
+
},
|
|
341
|
+
replay() {
|
|
342
|
+
fatal.replay();
|
|
343
|
+
},
|
|
344
|
+
store(error) {
|
|
345
|
+
return fatal.store(error);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
559
348
|
}
|
|
560
349
|
|
|
561
350
|
module.exports = { captureIssueWithAdmission, createFatalController };
|