@bugsee/react-native 0.0.0-stage → 7.0.0-beta2
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +557 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +962 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the exception payload the wrapper sends to the native SDKs (design
|
|
3
|
+
* §9.1, Phase 7 "The payload (exact)"). This is pure JS: both natives forward
|
|
4
|
+
* it verbatim, never parsing, logging, truncating or re-encoding it.
|
|
5
|
+
*
|
|
6
|
+
* `buildExceptionPayload` never throws. It reads no property of a thrown
|
|
7
|
+
* value except `name`, `message`, `stack` and `cause` -- every read goes
|
|
8
|
+
* through a helper that treats a throwing getter as if the property were
|
|
9
|
+
* absent -- so a hostile getter, a `Proxy` or a revoked `Proxy` cannot break
|
|
10
|
+
* it. A thrown non-`Error` is described (R9), never serialised: nothing else
|
|
11
|
+
* it carries is read, so nothing else it carries can leak into the payload.
|
|
12
|
+
*/
|
|
13
|
+
import { cleanSource, fileKey, parseStack, STACK_MAX_INPUT_LENGTH, type ParsedFrame } from './stack';
|
|
14
|
+
import { sha1Hex } from './sha1';
|
|
15
|
+
|
|
16
|
+
export const EXCEPTION_MAX_FRAMES = 256;
|
|
17
|
+
export const EXCEPTION_MAX_CAUSE_DEPTH = 10;
|
|
18
|
+
/**
|
|
19
|
+
* The most stack content (`error.stack`, `componentStack`, `fallbackStack`
|
|
20
|
+
* combined, in UTF-16 units) `buildExceptionPayload` will hand to
|
|
21
|
+
* `parseStack` for one call. `STACK_MAX_INPUT_LENGTH` bounds a single
|
|
22
|
+
* stack; nothing on its own bounded the *sum* across a cause chain's up to
|
|
23
|
+
* 11 nodes plus `componentStack`, so that total could still reach 12x a
|
|
24
|
+
* single node's own worst case (review N1). Shared across the whole tree
|
|
25
|
+
* via one mutable counter (`ParseBudget`): once it reaches zero, every
|
|
26
|
+
* later node's frames are `[]`, the same as if it had no stack at all.
|
|
27
|
+
*/
|
|
28
|
+
export const EXCEPTION_MAX_TOTAL_STACK_LENGTH = 128 * 1024;
|
|
29
|
+
/**
|
|
30
|
+
* The most a trimmed `reason` keeps of the original content, in UTF-16
|
|
31
|
+
* units. A reason actually cut is one unit longer than this: the appended
|
|
32
|
+
* `…` (`TRUNCATION_ELLIPSIS`) is not counted against the cap, so it is
|
|
33
|
+
* always visible evidence that a cut happened, matching 6.x.
|
|
34
|
+
*/
|
|
35
|
+
export const EXCEPTION_MAX_REASON_LENGTH = 8192;
|
|
36
|
+
/** `name`, trimmed to this many UTF-16 units (same surrogate-safe cut as `reason`). */
|
|
37
|
+
export const EXCEPTION_MAX_NAME_LENGTH = 256;
|
|
38
|
+
/** `traceRaw`, `data.source` and `data.member`, each trimmed to this many UTF-16 units. */
|
|
39
|
+
export const EXCEPTION_MAX_FIELD_LENGTH = 1024;
|
|
40
|
+
export const ERROR_BOUNDARY_CAUSE_NAME = 'ErrorBoundary Error';
|
|
41
|
+
|
|
42
|
+
const UNKNOWN_MEMBER = '<unknown>';
|
|
43
|
+
const TRUNCATION_ELLIPSIS = '…';
|
|
44
|
+
|
|
45
|
+
export interface ExceptionFrame {
|
|
46
|
+
traceRaw: string;
|
|
47
|
+
trace: string;
|
|
48
|
+
data: {
|
|
49
|
+
member: string;
|
|
50
|
+
source: string;
|
|
51
|
+
line: number | null;
|
|
52
|
+
column: number | null;
|
|
53
|
+
};
|
|
54
|
+
user?: boolean;
|
|
55
|
+
debug_id?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ExceptionNode {
|
|
59
|
+
name: string;
|
|
60
|
+
reason: string;
|
|
61
|
+
frames: ExceptionFrame[];
|
|
62
|
+
cause?: ExceptionNode;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface ExceptionPayload extends ExceptionNode {
|
|
66
|
+
signature: string;
|
|
67
|
+
platform_os: 'android' | 'ios';
|
|
68
|
+
debug_ids?: Record<string, string>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface PayloadInput {
|
|
72
|
+
error: unknown;
|
|
73
|
+
platformOS: 'android' | 'ios';
|
|
74
|
+
/** R10: the innermost cause, named `ERROR_BOUNDARY_CAUSE_NAME`. */
|
|
75
|
+
componentStack?: string;
|
|
76
|
+
/** A stack captured by the caller; used only when `error` is not an `Error` (Task 7.1b). */
|
|
77
|
+
fallbackStack?: string;
|
|
78
|
+
/** File key -> debug id (Task 7.3). Empty (or absent) until then. */
|
|
79
|
+
debugIds?: ReadonlyMap<string, string>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Reads `obj[key]`, treating a throwing getter (or any other failure) as absent. */
|
|
83
|
+
function safeGet(obj: object, key: string): unknown {
|
|
84
|
+
try {
|
|
85
|
+
return (obj as Record<string, unknown>)[key];
|
|
86
|
+
} catch {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function safeGetString(obj: object, key: string): string | undefined {
|
|
92
|
+
const value = safeGet(obj, key);
|
|
93
|
+
return typeof value === 'string' ? value : undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function safeIsError(value: unknown): value is Error {
|
|
97
|
+
try {
|
|
98
|
+
return value instanceof Error;
|
|
99
|
+
} catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isReferenceType(value: unknown): value is object {
|
|
105
|
+
return (typeof value === 'object' && value !== null) || typeof value === 'function';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* R9: a thrown non-`Error`'s name and reason. A string is the reason itself;
|
|
110
|
+
* an object (or function) with a string `message` gives that message, plus
|
|
111
|
+
* its `name` when that is also a string; anything else is
|
|
112
|
+
* `Non-Error thrown: <typeof>`.
|
|
113
|
+
*/
|
|
114
|
+
export function describeThrown(value: unknown): { name: string; reason: string } {
|
|
115
|
+
if (typeof value === 'string') {
|
|
116
|
+
return { name: 'Error', reason: value };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (isReferenceType(value)) {
|
|
120
|
+
const message = safeGetString(value, 'message');
|
|
121
|
+
if (message !== undefined) {
|
|
122
|
+
const name = safeGetString(value, 'name');
|
|
123
|
+
return { name: name || 'Error', reason: message };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return { name: 'Error', reason: `Non-Error thrown: ${typeof value}` };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Truncates to `max` UTF-16 units, appending `TRUNCATION_ELLIPSIS`, never splitting a surrogate pair. */
|
|
131
|
+
function truncate(raw: string, max: number): string {
|
|
132
|
+
if (raw.length <= max) {
|
|
133
|
+
return raw;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
let cut = max;
|
|
137
|
+
const codeBeforeCut = raw.charCodeAt(cut - 1);
|
|
138
|
+
if (codeBeforeCut >= 0xd800 && codeBeforeCut <= 0xdbff) {
|
|
139
|
+
cut -= 1;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return raw.slice(0, cut) + TRUNCATION_ELLIPSIS;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Trims and truncates to `EXCEPTION_MAX_REASON_LENGTH`, never splitting a surrogate pair. */
|
|
146
|
+
function normalizeReason(raw: string): string {
|
|
147
|
+
return truncate(raw.trim(), EXCEPTION_MAX_REASON_LENGTH);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Truncates to `EXCEPTION_MAX_NAME_LENGTH`. Not trimmed: the payload table
|
|
152
|
+
* defines `name` as "the error's `name` if it is a non-empty string", and a
|
|
153
|
+
* whitespace-only name is still non-empty by that definition (M7).
|
|
154
|
+
*/
|
|
155
|
+
function normalizeName(raw: string): string {
|
|
156
|
+
return truncate(raw, EXCEPTION_MAX_NAME_LENGTH);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Truncates `traceRaw`/`data.source`/`data.member` to `EXCEPTION_MAX_FIELD_LENGTH` (I1). */
|
|
160
|
+
function normalizeField(raw: string): string {
|
|
161
|
+
return truncate(raw, EXCEPTION_MAX_FIELD_LENGTH);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Strips a stack's own "Name: message" header (I2), matching 6.x's
|
|
166
|
+
* `getCleanStack`. Hermes and V8 prepend `<name>: <message>` before the
|
|
167
|
+
* real frames (or just `<message>` when `name` is `''`, or just `<name>`
|
|
168
|
+
* when `message` is `''`); JSC does not, so this is a no-op there. Tried
|
|
169
|
+
* longest-candidate-first so a message that itself starts with the bare
|
|
170
|
+
* name does not cause a partial strip.
|
|
171
|
+
*
|
|
172
|
+
* `name` here is the *raw* value read off the error (via `safeGetString`,
|
|
173
|
+
* so `''` when absent or non-string) -- not the display name `'Error'`
|
|
174
|
+
* falls back to -- because that fallback is exactly the case where V8 and
|
|
175
|
+
* Hermes write no name at all, only `message`, as the header (review N2).
|
|
176
|
+
*
|
|
177
|
+
* A candidate is accepted only when it is followed by the end of the
|
|
178
|
+
* string, `\n` or `\r`: `stack.startsWith(name)` alone is not enough,
|
|
179
|
+
* because a real frame's own function name can start with the error's
|
|
180
|
+
* name as plain text -- captured with JSC: `new TypeError('boom')` thrown
|
|
181
|
+
* from a function named `TypeErrorFactory` gives a stack whose first (and
|
|
182
|
+
* only) line is `TypeErrorFactory@file:2:22`, and `name` is `'TypeError'`.
|
|
183
|
+
* Without this check that line becomes `Factory@file:2:22`, a wrong
|
|
184
|
+
* member name.
|
|
185
|
+
*
|
|
186
|
+
* `message` may contain newlines; matching it as one literal prefix (rather
|
|
187
|
+
* than only its first line) strips a multi-line message in one step,
|
|
188
|
+
* including any later line that happens to look like a frame.
|
|
189
|
+
*
|
|
190
|
+
* Deliberately does not also strip the newline (`\n` or `\r\n`) left right
|
|
191
|
+
* after the header: `parseStack` already `trim()`s every line and skips a
|
|
192
|
+
* blank one, so whatever that leftover newline turns into -- an empty
|
|
193
|
+
* first "line", or a lone `\r` that trims to empty -- is silently absorbed
|
|
194
|
+
* there. Stripping it here too would be untestable dead weight, not extra
|
|
195
|
+
* safety.
|
|
196
|
+
*/
|
|
197
|
+
function stripKnownHeader(stack: string, name: string, message: string): string {
|
|
198
|
+
const candidates: string[] = [];
|
|
199
|
+
if (name.length > 0 && message.length > 0) {
|
|
200
|
+
candidates.push(`${name}: ${message}`);
|
|
201
|
+
}
|
|
202
|
+
if (name.length > 0) {
|
|
203
|
+
candidates.push(name);
|
|
204
|
+
} else if (message.length > 0) {
|
|
205
|
+
candidates.push(message);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
for (const candidate of candidates) {
|
|
209
|
+
if (stack.startsWith(candidate)) {
|
|
210
|
+
const next = stack.charAt(candidate.length);
|
|
211
|
+
if (next === '' || next === '\n' || next === '\r') {
|
|
212
|
+
return stack.slice(candidate.length);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return stack;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function buildTrace(member: string, source: string, line: number | null, column: number | null): string {
|
|
221
|
+
let location = source;
|
|
222
|
+
if (line !== null) {
|
|
223
|
+
location += `:${line}`;
|
|
224
|
+
}
|
|
225
|
+
if (column !== null) {
|
|
226
|
+
location += `:${column}`;
|
|
227
|
+
}
|
|
228
|
+
return `${member} () (${location})`;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function isUserSource(source: string): boolean {
|
|
232
|
+
return !source.includes('node_modules') && !source.includes('native code') && !source.includes('(native)');
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* React 19's `describeBuiltInComponentFrame` (`ReactFabric-dev.js`) emits a
|
|
237
|
+
* synthetic frame for a built-in host component (`View`, `Text`, ...) with
|
|
238
|
+
* no real source: `"View (<anonymous>)"` on an engine whose own stacks say
|
|
239
|
+
* "at" (Hermes, V8 -- `file` is the literal string `<anonymous>`, with no
|
|
240
|
+
* line/column at all, so `user` is already `false` there); `"View@unknown:0:0"`
|
|
241
|
+
* on one that does not (JSC -- `file` is the literal string `unknown`, with
|
|
242
|
+
* line and column both `0`, which are *not* `null`). Only the second shape
|
|
243
|
+
* needs an explicit check: `0` is a real number, so without it this parses
|
|
244
|
+
* as a user frame (review N4).
|
|
245
|
+
*/
|
|
246
|
+
function isBuiltInComponentSentinel(file: string, line: number | null, column: number | null): boolean {
|
|
247
|
+
return file === 'unknown' && line === 0 && column === 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function toExceptionFrame(frame: ParsedFrame, debugIds: ReadonlyMap<string, string> | undefined): ExceptionFrame {
|
|
251
|
+
const source = normalizeField(cleanSource(frame.file));
|
|
252
|
+
const member = normalizeField(frame.methodName || UNKNOWN_MEMBER);
|
|
253
|
+
const { lineNumber: line, column } = frame;
|
|
254
|
+
|
|
255
|
+
const exceptionFrame: ExceptionFrame = {
|
|
256
|
+
traceRaw: normalizeField(frame.raw),
|
|
257
|
+
trace: buildTrace(member, source, line, column),
|
|
258
|
+
data: { member, source, line, column },
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
if (frame.file !== null) {
|
|
262
|
+
// "its file" (the payload table's `user` row) -- checked on the frame's
|
|
263
|
+
// own file, not the cleaned `source`, matching the spec's wording (M6).
|
|
264
|
+
// In practice this never changes the result: none of `cleanSource`'s
|
|
265
|
+
// five steps can remove `node_modules`, `native code`, `(native)` or
|
|
266
|
+
// the built-in-component sentinel `unknown` (review N4).
|
|
267
|
+
exceptionFrame.user =
|
|
268
|
+
line !== null &&
|
|
269
|
+
column !== null &&
|
|
270
|
+
!isBuiltInComponentSentinel(frame.file, line, column) &&
|
|
271
|
+
isUserSource(frame.file);
|
|
272
|
+
|
|
273
|
+
const debugId = debugIds?.get(fileKey(frame.file));
|
|
274
|
+
if (debugId !== undefined) {
|
|
275
|
+
exceptionFrame.debug_id = debugId;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return exceptionFrame;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** A mutable counter shared across one `buildExceptionPayload` call's whole node tree. */
|
|
283
|
+
interface ParseBudget {
|
|
284
|
+
remaining: number;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function buildFrames(
|
|
288
|
+
stack: string | undefined,
|
|
289
|
+
debugIds: ReadonlyMap<string, string> | undefined,
|
|
290
|
+
budget: ParseBudget,
|
|
291
|
+
): ExceptionFrame[] {
|
|
292
|
+
if (typeof stack !== 'string' || budget.remaining <= 0) {
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const takeLength = Math.min(stack.length, budget.remaining, STACK_MAX_INPUT_LENGTH);
|
|
297
|
+
budget.remaining -= takeLength;
|
|
298
|
+
|
|
299
|
+
return parseStack(stack.slice(0, takeLength), EXCEPTION_MAX_FRAMES).map((frame) =>
|
|
300
|
+
toExceptionFrame(frame, debugIds),
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function buildNode(
|
|
305
|
+
value: unknown,
|
|
306
|
+
depth: number,
|
|
307
|
+
seen: WeakSet<object>,
|
|
308
|
+
fallbackStack: string | undefined,
|
|
309
|
+
debugIds: ReadonlyMap<string, string> | undefined,
|
|
310
|
+
budget: ParseBudget,
|
|
311
|
+
): ExceptionNode {
|
|
312
|
+
let name: string;
|
|
313
|
+
let rawReason: string;
|
|
314
|
+
let frames: ExceptionFrame[];
|
|
315
|
+
let rawCause: unknown;
|
|
316
|
+
|
|
317
|
+
if (safeIsError(value)) {
|
|
318
|
+
const errorName = safeGetString(value, 'name') ?? '';
|
|
319
|
+
name = errorName || 'Error';
|
|
320
|
+
rawReason = safeGetString(value, 'message') ?? '';
|
|
321
|
+
const stackVal = safeGetString(value, 'stack');
|
|
322
|
+
// The *raw* name (which may be '') goes to stripKnownHeader, not the
|
|
323
|
+
// display fallback `name` above -- see its own comment (review N2).
|
|
324
|
+
const strippedStack =
|
|
325
|
+
stackVal !== undefined ? stripKnownHeader(stackVal, errorName, rawReason) : undefined;
|
|
326
|
+
frames = buildFrames(strippedStack, debugIds, budget);
|
|
327
|
+
rawCause = safeGet(value, 'cause');
|
|
328
|
+
} else {
|
|
329
|
+
const described = describeThrown(value);
|
|
330
|
+
name = described.name;
|
|
331
|
+
rawReason = described.reason;
|
|
332
|
+
// Recursive calls (building a cause) never pass a fallback stack -- it is
|
|
333
|
+
// only ever meaningful for the top-level thrown value.
|
|
334
|
+
frames = buildFrames(fallbackStack, debugIds, budget);
|
|
335
|
+
rawCause = undefined;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const node: ExceptionNode = {
|
|
339
|
+
name: normalizeName(name),
|
|
340
|
+
reason: normalizeReason(rawReason),
|
|
341
|
+
frames,
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
if (rawCause !== undefined && depth < EXCEPTION_MAX_CAUSE_DEPTH) {
|
|
345
|
+
const repeatKey = isReferenceType(rawCause) ? rawCause : undefined;
|
|
346
|
+
const isRepeat = repeatKey !== undefined && seen.has(repeatKey);
|
|
347
|
+
if (!isRepeat) {
|
|
348
|
+
if (repeatKey !== undefined) {
|
|
349
|
+
seen.add(repeatKey);
|
|
350
|
+
}
|
|
351
|
+
node.cause = buildNode(rawCause, depth + 1, seen, undefined, debugIds, budget);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
return node;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** Appends the R10 boundary node after the deepest node already in `root`'s chain. */
|
|
359
|
+
function attachBoundaryNode(
|
|
360
|
+
root: ExceptionNode,
|
|
361
|
+
componentStack: string,
|
|
362
|
+
debugIds: ReadonlyMap<string, string> | undefined,
|
|
363
|
+
budget: ParseBudget,
|
|
364
|
+
): void {
|
|
365
|
+
let tail = root;
|
|
366
|
+
while (tail.cause !== undefined) {
|
|
367
|
+
tail = tail.cause;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
tail.cause = {
|
|
371
|
+
name: ERROR_BOUNDARY_CAUSE_NAME,
|
|
372
|
+
reason: '',
|
|
373
|
+
frames: buildFrames(componentStack, debugIds, budget),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function signatureInput(node: ExceptionNode): string {
|
|
378
|
+
let input = node.name;
|
|
379
|
+
for (const frame of node.frames) {
|
|
380
|
+
input += frame.trace;
|
|
381
|
+
}
|
|
382
|
+
if (node.cause) {
|
|
383
|
+
input += signatureInput(node.cause);
|
|
384
|
+
}
|
|
385
|
+
return input;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function buildPayloadUnsafe(input: PayloadInput): ExceptionPayload {
|
|
389
|
+
const seen = new WeakSet<object>();
|
|
390
|
+
if (isReferenceType(input.error)) {
|
|
391
|
+
seen.add(input.error);
|
|
392
|
+
}
|
|
393
|
+
const budget: ParseBudget = { remaining: EXCEPTION_MAX_TOTAL_STACK_LENGTH };
|
|
394
|
+
|
|
395
|
+
const root = buildNode(input.error, 0, seen, input.fallbackStack, input.debugIds, budget);
|
|
396
|
+
|
|
397
|
+
if (input.componentStack) {
|
|
398
|
+
attachBoundaryNode(root, input.componentStack, input.debugIds, budget);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
const payload: ExceptionPayload = {
|
|
402
|
+
name: root.name,
|
|
403
|
+
reason: root.reason,
|
|
404
|
+
frames: root.frames,
|
|
405
|
+
...(root.cause !== undefined ? { cause: root.cause } : {}),
|
|
406
|
+
signature: sha1Hex(signatureInput(root)),
|
|
407
|
+
platform_os: input.platformOS,
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
if (input.debugIds && input.debugIds.size > 0) {
|
|
411
|
+
// Keyed by the cleaned source, exactly as frames[].data.source is, so a
|
|
412
|
+
// consumer can join the two. The per-frame lookup above stays on fileKey
|
|
413
|
+
// (the registration's join key); two raw paths that clean to one source
|
|
414
|
+
// keep the first id.
|
|
415
|
+
const keyed: Record<string, string> = {};
|
|
416
|
+
for (const [file, id] of input.debugIds) {
|
|
417
|
+
const key = cleanSource(file);
|
|
418
|
+
if (!(key in keyed)) {
|
|
419
|
+
keyed[key] = id;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
payload.debug_ids = keyed;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return payload;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** A minimal, always-constructible payload for the (unreachable in practice) case where `input` itself cannot be read. */
|
|
429
|
+
function buildFallbackPayload(input: PayloadInput): ExceptionPayload {
|
|
430
|
+
let platformOS: 'android' | 'ios' = 'ios';
|
|
431
|
+
try {
|
|
432
|
+
const candidate = input.platformOS;
|
|
433
|
+
if (candidate === 'android' || candidate === 'ios') {
|
|
434
|
+
platformOS = candidate;
|
|
435
|
+
}
|
|
436
|
+
} catch {
|
|
437
|
+
// Keep the default.
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const name = 'Error';
|
|
441
|
+
return {
|
|
442
|
+
name,
|
|
443
|
+
reason: `Non-Error thrown: object`,
|
|
444
|
+
frames: [],
|
|
445
|
+
signature: sha1Hex(name),
|
|
446
|
+
platform_os: platformOS,
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function buildExceptionPayload(input: PayloadInput): ExceptionPayload {
|
|
451
|
+
try {
|
|
452
|
+
return buildPayloadUnsafe(input);
|
|
453
|
+
} catch {
|
|
454
|
+
return buildFallbackPayload(input);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds and crosses a JS exception payload to the TurboModule stubs.
|
|
3
|
+
*
|
|
4
|
+
* Dedupes object values through a WeakSet (`markReported`). Handled
|
|
5
|
+
* `AggregateError`s are split (R14, first {@link EXCEPTION_MAX_AGGREGATE});
|
|
6
|
+
* unhandled ones stay one report. Never throws from `reportHandled`; never
|
|
7
|
+
* rejects from `reportUnhandled`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { Platform } from 'react-native';
|
|
11
|
+
import NativeBugsee from '../NativeBugsee';
|
|
12
|
+
import { encodeBridgeObject } from '../bridge/json';
|
|
13
|
+
import { currentDebugIds } from './debugIds';
|
|
14
|
+
import { buildExceptionPayload } from './payload';
|
|
15
|
+
import { encodeExceptionOptions, type ExceptionOptions } from './options';
|
|
16
|
+
|
|
17
|
+
/** How long JS waits for native to take an unhandled exception: iOS. */
|
|
18
|
+
export const UNHANDLED_REPORT_WAIT_MS = 1500;
|
|
19
|
+
/**
|
|
20
|
+
* The same on Android. Android's native call has no deadline of its own and
|
|
21
|
+
* resolves the moment the SDK returns (median about 1.15 s on a mid-range
|
|
22
|
+
* phone), so this only bounds a hung SDK. It must not be shorter than the
|
|
23
|
+
* SDK's own worst case: 7.3.1 persists the exception payload only after the
|
|
24
|
+
* report's view-hierarchy step, which alone may take 1000 + 500 + 250 ms, and
|
|
25
|
+
* a fatal's process dies soon after this wait ends. At 1500 ms 1 natural JS
|
|
26
|
+
* fatal in 10 lost its payload (`crash` absent `export_failed`;
|
|
27
|
+
* https://github.com/bugsee/bugsee-android/issues/251).
|
|
28
|
+
*/
|
|
29
|
+
export const UNHANDLED_REPORT_WAIT_MS_ANDROID = 5000;
|
|
30
|
+
|
|
31
|
+
/** {@link UNHANDLED_REPORT_WAIT_MS_ANDROID} on Android, else {@link UNHANDLED_REPORT_WAIT_MS}. */
|
|
32
|
+
export function unhandledReportWaitMs(): number {
|
|
33
|
+
return Platform.OS === 'android' ? UNHANDLED_REPORT_WAIT_MS_ANDROID : UNHANDLED_REPORT_WAIT_MS;
|
|
34
|
+
}
|
|
35
|
+
export const EXCEPTION_MAX_AGGREGATE = 10;
|
|
36
|
+
|
|
37
|
+
const reported = new WeakSet<object>();
|
|
38
|
+
|
|
39
|
+
/** true the first time an object is seen (WeakSet); always true for a primitive. */
|
|
40
|
+
export function markReported(error: unknown): boolean {
|
|
41
|
+
if (error === null || (typeof error !== 'object' && typeof error !== 'function')) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
if (reported.has(error as object)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
reported.add(error as object);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type Extras = { componentStack?: string; fallbackStack?: string };
|
|
52
|
+
|
|
53
|
+
function platformOS(): 'android' | 'ios' {
|
|
54
|
+
// PayloadInput accepts only these two; other Platform.OS values follow iOS.
|
|
55
|
+
// Stryker disable next-line ConditionalExpression,StringLiteral -- ios branch needs a Platform.OS='ios' mock; android-only suite leaves the ios literal equivalent to ""
|
|
56
|
+
return Platform.OS === 'android' ? 'android' : 'ios';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function payloadJson(error: unknown, extras?: Extras): string {
|
|
60
|
+
const payload = buildExceptionPayload({
|
|
61
|
+
error,
|
|
62
|
+
platformOS: platformOS(),
|
|
63
|
+
componentStack: extras?.componentStack,
|
|
64
|
+
fallbackStack: extras?.fallbackStack,
|
|
65
|
+
debugIds: currentDebugIds(),
|
|
66
|
+
});
|
|
67
|
+
return encodeBridgeObject(payload as unknown as Record<string, unknown>);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isAggregateError(value: unknown): value is AggregateError {
|
|
71
|
+
// Stryker disable next-line ConditionalExpression,StringLiteral -- AggregateError is always defined in our Jest/RN targets; the typeof guard is a belt-and-braces for older engines
|
|
72
|
+
return typeof AggregateError !== 'undefined' && value instanceof AggregateError;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function sendHandled(
|
|
76
|
+
error: unknown,
|
|
77
|
+
options: ExceptionOptions | undefined,
|
|
78
|
+
extras: Extras | undefined,
|
|
79
|
+
): void {
|
|
80
|
+
const optionsJson = encodeExceptionOptions(options);
|
|
81
|
+
NativeBugsee.logException(payloadJson(error, extras), optionsJson);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Reports `error` as handled. Never throws; R14 splits an AggregateError into
|
|
86
|
+
* at most {@link EXCEPTION_MAX_AGGREGATE} inner reports.
|
|
87
|
+
*
|
|
88
|
+
* Callers claim the value with {@link markReported} first. This function does
|
|
89
|
+
* not re-claim the top-level `error` (handlers and the facade share one
|
|
90
|
+
* WeakSet); it still marks AggregateError inners so a shared Error crosses
|
|
91
|
+
* once whichever route saw it first.
|
|
92
|
+
*/
|
|
93
|
+
export function reportHandled(
|
|
94
|
+
error: unknown,
|
|
95
|
+
options?: ExceptionOptions,
|
|
96
|
+
extras?: Extras,
|
|
97
|
+
): void {
|
|
98
|
+
try {
|
|
99
|
+
if (isAggregateError(error)) {
|
|
100
|
+
const inners = Array.isArray(error.errors) ? error.errors : [];
|
|
101
|
+
const limit = Math.min(inners.length, EXCEPTION_MAX_AGGREGATE);
|
|
102
|
+
for (let i = 0; i < limit; i += 1) {
|
|
103
|
+
try {
|
|
104
|
+
if (!markReported(inners[i])) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
sendHandled(inners[i], options, extras);
|
|
108
|
+
} catch {
|
|
109
|
+
// A single inner must not stop the rest, and must not escape.
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
sendHandled(error, options, extras);
|
|
115
|
+
} catch {
|
|
116
|
+
// never throws
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let warnedUnhandledNativeFailure = false;
|
|
121
|
+
|
|
122
|
+
function warnUnhandledNativeFailureOnce(): void {
|
|
123
|
+
if (warnedUnhandledNativeFailure) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
warnedUnhandledNativeFailure = true;
|
|
127
|
+
console.warn('[Bugsee] logUnhandledException native call failed');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Reports `error` as unhandled. Resolves when native resolves or after
|
|
132
|
+
* {@link unhandledReportWaitMs}, whichever is first; never rejects.
|
|
133
|
+
*
|
|
134
|
+
* Callers claim the value with {@link markReported} first (same shared
|
|
135
|
+
* WeakSet as {@link reportHandled}).
|
|
136
|
+
*/
|
|
137
|
+
export async function reportUnhandled(
|
|
138
|
+
error: unknown,
|
|
139
|
+
extras?: Extras,
|
|
140
|
+
): Promise<void> {
|
|
141
|
+
let nativePromise: Promise<void>;
|
|
142
|
+
try {
|
|
143
|
+
nativePromise = Promise.resolve(NativeBugsee.logUnhandledException(payloadJson(error, extras)));
|
|
144
|
+
} catch {
|
|
145
|
+
warnUnhandledNativeFailureOnce();
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const guarded = nativePromise.then(
|
|
150
|
+
() => undefined,
|
|
151
|
+
() => {
|
|
152
|
+
warnUnhandledNativeFailureOnce();
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
157
|
+
const timeout = new Promise<void>((resolve) => {
|
|
158
|
+
timeoutId = setTimeout(resolve, unhandledReportWaitMs());
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
await Promise.race([guarded, timeout]);
|
|
163
|
+
} finally {
|
|
164
|
+
// Stryker disable all -- clearTimeout is unobservable in unit tests; emptying this finally is equivalent under the suite
|
|
165
|
+
if (timeoutId !== undefined) {
|
|
166
|
+
clearTimeout(timeoutId);
|
|
167
|
+
}
|
|
168
|
+
// Stryker restore all
|
|
169
|
+
}
|
|
170
|
+
}
|