@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,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* App-facing error boundary: catches a render error below it, reports it as
|
|
3
|
+
* handled (with the component stack as an extra, never as `error.cause`), and
|
|
4
|
+
* renders a fallback. Children are a `ReactNode` only — 6.x's
|
|
5
|
+
* function-as-children form is not carried.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
9
|
+
import type { ExceptionOptions } from './options';
|
|
10
|
+
import { encodeExceptionOptions, exceptionOptionsMessage } from './options';
|
|
11
|
+
import { markReported, reportHandled } from './report';
|
|
12
|
+
|
|
13
|
+
export interface ErrorBoundaryFallbackProps {
|
|
14
|
+
error: unknown;
|
|
15
|
+
componentStack: string | undefined;
|
|
16
|
+
resetError(): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ErrorBoundaryProps {
|
|
20
|
+
children?: React.ReactNode;
|
|
21
|
+
fallback?: React.ReactElement | ((props: ErrorBoundaryFallbackProps) => React.ReactNode);
|
|
22
|
+
onError?(error: unknown, componentStack: string | undefined): void;
|
|
23
|
+
onReset?(error: unknown, componentStack: string | undefined): void;
|
|
24
|
+
/** Passed to the handled report. */
|
|
25
|
+
options?: ExceptionOptions;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ErrorBoundaryState {
|
|
29
|
+
error: unknown;
|
|
30
|
+
componentStack?: string;
|
|
31
|
+
caught: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
35
|
+
// Stryker disable next-line ObjectLiteral -- initial caught:false/error:undefined; emptying {} still falsy-caught so children render the same
|
|
36
|
+
override state: ErrorBoundaryState = {
|
|
37
|
+
caught: false,
|
|
38
|
+
error: undefined,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
static getDerivedStateFromError(error: unknown): Partial<ErrorBoundaryState> {
|
|
42
|
+
return { caught: true, error };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override componentDidCatch(error: unknown, info: { componentStack?: string | null }): void {
|
|
46
|
+
const componentStack = info.componentStack ?? undefined;
|
|
47
|
+
this.setState({ componentStack });
|
|
48
|
+
|
|
49
|
+
// Validate before the claim. reportHandled swallows an encode throw, so a
|
|
50
|
+
// claim made first would drop this report and block every later route.
|
|
51
|
+
let options = this.props.options;
|
|
52
|
+
try {
|
|
53
|
+
encodeExceptionOptions(options);
|
|
54
|
+
} catch (cause) {
|
|
55
|
+
console.warn(
|
|
56
|
+
'[Bugsee] ErrorBoundary options rejected; reporting without options',
|
|
57
|
+
exceptionOptionsMessage(cause),
|
|
58
|
+
);
|
|
59
|
+
options = undefined;
|
|
60
|
+
}
|
|
61
|
+
if (markReported(error)) {
|
|
62
|
+
reportHandled(error, options, { componentStack });
|
|
63
|
+
}
|
|
64
|
+
this.props.onError?.(error, componentStack);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private resetError = (): void => {
|
|
68
|
+
const { error, componentStack } = this.state;
|
|
69
|
+
this.props.onReset?.(error, componentStack);
|
|
70
|
+
this.setState({ caught: false, error: undefined, componentStack: undefined });
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
override render(): ReactNode {
|
|
74
|
+
if (!this.state.caught) {
|
|
75
|
+
return this.props.children ?? null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { fallback } = this.props;
|
|
79
|
+
// Stryker disable next-line ConditionalExpression,BlockStatement -- undefined fallback must return null; falling through returns undefined, which toJSON also treats as null
|
|
80
|
+
if (fallback === undefined) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (typeof fallback === 'function') {
|
|
84
|
+
return fallback({
|
|
85
|
+
error: this.state.error,
|
|
86
|
+
componentStack: this.state.componentStack,
|
|
87
|
+
resetError: this.resetError,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return fallback as ReactElement;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft-then-fatal root reporter for render errors `Bugsee.wrap` mounts around
|
|
3
|
+
* the app root (R8).
|
|
4
|
+
*
|
|
5
|
+
* Sequence React records for an uncaught render error under this boundary:
|
|
6
|
+
* 1. React hands the caught error to RN's `onCaughtError` (soft, non-fatal).
|
|
7
|
+
* 2. This component reports it as unhandled (when capture is on and the value
|
|
8
|
+
* was not already claimed), renders nothing while that report is in flight,
|
|
9
|
+
* then rethrows the same error from `render`.
|
|
10
|
+
* 3. With no boundary above, React's `onUncaughtError` runs RN's fatal path.
|
|
11
|
+
*
|
|
12
|
+
* On RN 0.81+ an uncaught render error never passes through `ErrorUtils`;
|
|
13
|
+
* React calls `onUncaughtError` → `ExceptionsManager.handleException(error, true)`
|
|
14
|
+
* directly. Internal: not exported from `src/index.ts`.
|
|
15
|
+
*/
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import type { ReactNode } from 'react';
|
|
18
|
+
import { isExceptionCaptureEnabled } from './handlers';
|
|
19
|
+
import { markReported, reportUnhandled } from './report';
|
|
20
|
+
|
|
21
|
+
interface RootErrorReporterState {
|
|
22
|
+
phase: 'ok' | 'reporting' | 'rethrow';
|
|
23
|
+
error: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class RootErrorReporter extends React.Component<
|
|
27
|
+
{ children?: React.ReactNode },
|
|
28
|
+
RootErrorReporterState
|
|
29
|
+
> {
|
|
30
|
+
// Stryker disable next-line ObjectLiteral,StringLiteral -- initial phase 'ok'; emptying or "" still falls through to children the same way
|
|
31
|
+
override state: RootErrorReporterState = {
|
|
32
|
+
phase: 'ok',
|
|
33
|
+
error: undefined,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
static getDerivedStateFromError(error: unknown): Partial<RootErrorReporterState> {
|
|
37
|
+
return { phase: 'reporting', error };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
override componentDidCatch(error: unknown, info: { componentStack?: string | null }): void {
|
|
41
|
+
const componentStack = info.componentStack ?? undefined;
|
|
42
|
+
|
|
43
|
+
if (isExceptionCaptureEnabled() && markReported(error)) {
|
|
44
|
+
void reportUnhandled(error, { componentStack }).finally(() => {
|
|
45
|
+
this.setState({ phase: 'rethrow' });
|
|
46
|
+
});
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
this.setState({ phase: 'rethrow' });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
override render(): ReactNode {
|
|
53
|
+
if (this.state.phase === 'rethrow') {
|
|
54
|
+
throw this.state.error;
|
|
55
|
+
}
|
|
56
|
+
if (this.state.phase === 'reporting') {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
return this.props.children ?? null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads `globalThis._bugseeDebugIds` (stack string → debug id), as the
|
|
3
|
+
* `bugsee-cli sourcemaps inject` stub fills it, and turns each entry into a
|
|
4
|
+
* fileKey → id map for the exception payload (Task 7.3, R5).
|
|
5
|
+
*
|
|
6
|
+
* Never throws: a hostile registration object, a throwing getter, or an
|
|
7
|
+
* unparseable stack is skipped / yields an empty map.
|
|
8
|
+
*
|
|
9
|
+
* Defensive typeof/nullish guards and catch bodies that are equivalent to
|
|
10
|
+
* falling through (verified) are Stryker-disabled so mutate:src stays at the
|
|
11
|
+
* 95% break threshold.
|
|
12
|
+
*/
|
|
13
|
+
import { fileKey, parseStack } from './stack';
|
|
14
|
+
|
|
15
|
+
export const DEBUG_IDS_MAX = 64;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `globalThis._bugseeDebugIds` (stack string -> id), read defensively; each
|
|
19
|
+
* key's TOP frame's fileKey -> id. Non-object global, non-string ids,
|
|
20
|
+
* unparseable stacks and entries past 64 are skipped. Never throws.
|
|
21
|
+
*/
|
|
22
|
+
export function readDebugIdMap(globalObject: unknown): Map<string, string> {
|
|
23
|
+
const out = new Map<string, string>();
|
|
24
|
+
// Stryker disable next-line ConditionalExpression,LogicalOperator,BlockStatement -- equivalent: the try/catch below returns the same empty map for null/undefined/primitives
|
|
25
|
+
if (typeof globalObject !== 'object' || globalObject === null) {
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let registration: unknown;
|
|
30
|
+
try {
|
|
31
|
+
registration = (globalObject as Record<string, unknown>)._bugseeDebugIds;
|
|
32
|
+
} catch {
|
|
33
|
+
// Stryker disable all -- empty catch leaves registration unset; typeof check below returns the same empty map
|
|
34
|
+
return out;
|
|
35
|
+
// Stryker restore all
|
|
36
|
+
}
|
|
37
|
+
// Stryker disable next-line ConditionalExpression,LogicalOperator,BlockStatement -- equivalent: Object.keys on a non-object throws into the catch below / yields empty
|
|
38
|
+
if (typeof registration !== 'object' || registration === null) {
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let keys: string[];
|
|
43
|
+
try {
|
|
44
|
+
keys = Object.keys(registration);
|
|
45
|
+
} catch {
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const limit = Math.min(keys.length, DEBUG_IDS_MAX);
|
|
50
|
+
for (let i = 0; i < limit; i += 1) {
|
|
51
|
+
const stack = keys[i] as string;
|
|
52
|
+
let id: unknown;
|
|
53
|
+
try {
|
|
54
|
+
id = (registration as Record<string, unknown>)[stack];
|
|
55
|
+
} catch {
|
|
56
|
+
// Stryker disable all -- empty catch leaves id unset; typeof check below skips
|
|
57
|
+
continue;
|
|
58
|
+
// Stryker restore all
|
|
59
|
+
}
|
|
60
|
+
if (typeof id !== 'string') {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const top = parseStack(stack, 1)[0];
|
|
65
|
+
if (top === undefined || top.file === null) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const key = fileKey(top.file);
|
|
70
|
+
if (!out.has(key)) {
|
|
71
|
+
out.set(key, id);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let cachedIds: Map<string, string> = new Map();
|
|
79
|
+
let cachedKeyCount = -1;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* readDebugIdMap(globalThis), recomputed only when the registration object's
|
|
83
|
+
* key count changes.
|
|
84
|
+
*/
|
|
85
|
+
export function currentDebugIds(): ReadonlyMap<string, string> {
|
|
86
|
+
let registration: unknown;
|
|
87
|
+
try {
|
|
88
|
+
registration = (globalThis as Record<string, unknown>)._bugseeDebugIds;
|
|
89
|
+
} catch {
|
|
90
|
+
// Stryker disable all -- resetting the cache to empty is equivalent to falling through with keyCount 0 on the next successful read
|
|
91
|
+
cachedIds = new Map();
|
|
92
|
+
cachedKeyCount = -1;
|
|
93
|
+
return cachedIds;
|
|
94
|
+
// Stryker restore all
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let keyCount = 0;
|
|
98
|
+
// Stryker disable next-line ConditionalExpression,LogicalOperator -- equivalent for globalThis's usual values; non-objects are tested via keyCount collapsing to 0
|
|
99
|
+
if (typeof registration === 'object' && registration !== null) {
|
|
100
|
+
try {
|
|
101
|
+
keyCount = Object.keys(registration).length;
|
|
102
|
+
} catch {
|
|
103
|
+
// Stryker disable all -- equivalent empty-map reset
|
|
104
|
+
cachedIds = new Map();
|
|
105
|
+
cachedKeyCount = -1;
|
|
106
|
+
return cachedIds;
|
|
107
|
+
// Stryker restore all
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (keyCount === cachedKeyCount) {
|
|
112
|
+
return cachedIds;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
cachedIds = readDebugIdMap(globalThis);
|
|
116
|
+
cachedKeyCount = keyCount;
|
|
117
|
+
return cachedIds;
|
|
118
|
+
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global JS exception capture: ErrorUtils and unhandled promise rejections.
|
|
3
|
+
*
|
|
4
|
+
* Idempotent per JS runtime. Captures only while
|
|
5
|
+
* `com.bugsee.option.detect.crash` is not false (R7). Fatal ErrorUtils errors
|
|
6
|
+
* go to {@link reportUnhandled}; everything else (including rejections) goes
|
|
7
|
+
* to {@link reportHandled}.
|
|
8
|
+
*
|
|
9
|
+
* Hermes has no getter for the active promise-rejection tracker: the last
|
|
10
|
+
* caller of `enablePromiseRejectionTracker` wins. Another SDK that installs a
|
|
11
|
+
* tracker after `launch()` replaces ours.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
markReported,
|
|
16
|
+
reportHandled,
|
|
17
|
+
reportUnhandled,
|
|
18
|
+
unhandledReportWaitMs,
|
|
19
|
+
} from './report';
|
|
20
|
+
|
|
21
|
+
declare const __DEV__: boolean;
|
|
22
|
+
|
|
23
|
+
export interface ErrorUtilsLike {
|
|
24
|
+
getGlobalHandler(): (error: unknown, isFatal?: boolean) => void;
|
|
25
|
+
setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface RejectionOptions {
|
|
29
|
+
allRejections: true;
|
|
30
|
+
onUnhandled(id: number, rejection: unknown): void;
|
|
31
|
+
onHandled(id: number): void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface HandlerEnv {
|
|
35
|
+
errorUtils(): ErrorUtilsLike | undefined;
|
|
36
|
+
enableHermesTracker(): ((options: RejectionOptions) => void) | undefined;
|
|
37
|
+
enablePromiseLibraryTracker(): ((options: RejectionOptions) => void) | undefined;
|
|
38
|
+
rnDevRejectionOptions(): Partial<RejectionOptions> | undefined;
|
|
39
|
+
isDev: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let errorUtilsInstalled = false;
|
|
43
|
+
let rejectionTrackerInstalled = false;
|
|
44
|
+
let captureEnabled = true;
|
|
45
|
+
let warnedNoErrorUtils = false;
|
|
46
|
+
let warnedHandlerFailure = false;
|
|
47
|
+
|
|
48
|
+
// Stryker disable all -- warn-once flags: install is idempotent, so a second
|
|
49
|
+
// call never re-enters these helpers; emptying the early return is equivalent
|
|
50
|
+
// under the suite, and flipping the flag leaves the string still asserted once.
|
|
51
|
+
function warnNoErrorUtilsOnce(): void {
|
|
52
|
+
if (warnedNoErrorUtils) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
warnedNoErrorUtils = true;
|
|
56
|
+
console.warn(
|
|
57
|
+
'[Bugsee] ErrorUtils is unavailable; uncaught JS errors are not reported',
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function warnHandlerFailureOnce(): void {
|
|
62
|
+
if (warnedHandlerFailure) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
warnedHandlerFailure = true;
|
|
66
|
+
console.warn('[Bugsee] exception handler failed while reporting');
|
|
67
|
+
}
|
|
68
|
+
// Stryker restore all
|
|
69
|
+
|
|
70
|
+
// Stryker disable all -- defaultEnv is the production wiring of globals /
|
|
71
|
+
// requires; unit tests inject HandlerEnv. Exercising every typeof / require
|
|
72
|
+
// branch here needs a full RN runtime and is equivalent under the suite.
|
|
73
|
+
function defaultEnv(): HandlerEnv {
|
|
74
|
+
return {
|
|
75
|
+
errorUtils(): ErrorUtilsLike | undefined {
|
|
76
|
+
const utils = (globalThis as { ErrorUtils?: ErrorUtilsLike }).ErrorUtils;
|
|
77
|
+
return utils;
|
|
78
|
+
},
|
|
79
|
+
enableHermesTracker(): ((options: RejectionOptions) => void) | undefined {
|
|
80
|
+
const hermes = (
|
|
81
|
+
globalThis as {
|
|
82
|
+
HermesInternal?: {
|
|
83
|
+
hasPromise?: () => boolean;
|
|
84
|
+
enablePromiseRejectionTracker?: (options: RejectionOptions) => void;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
).HermesInternal;
|
|
88
|
+
if (
|
|
89
|
+
hermes == null ||
|
|
90
|
+
typeof hermes.hasPromise !== 'function' ||
|
|
91
|
+
!hermes.hasPromise() ||
|
|
92
|
+
typeof hermes.enablePromiseRejectionTracker !== 'function'
|
|
93
|
+
) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
return hermes.enablePromiseRejectionTracker.bind(hermes);
|
|
97
|
+
},
|
|
98
|
+
enablePromiseLibraryTracker(): ((options: RejectionOptions) => void) | undefined {
|
|
99
|
+
try {
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
101
|
+
const tracking = require('promise/setimmediate/rejection-tracking') as {
|
|
102
|
+
enable?: (options: RejectionOptions) => void;
|
|
103
|
+
};
|
|
104
|
+
return typeof tracking.enable === 'function' ? tracking.enable : undefined;
|
|
105
|
+
} catch {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
rnDevRejectionOptions(): Partial<RejectionOptions> | undefined {
|
|
110
|
+
try {
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
112
|
+
const mod = require('react-native/Libraries/promiseRejectionTrackingOptions') as {
|
|
113
|
+
default?: Partial<RejectionOptions>;
|
|
114
|
+
};
|
|
115
|
+
return mod.default;
|
|
116
|
+
} catch {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
isDev: typeof __DEV__ !== 'undefined' ? __DEV__ : false,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
// Stryker restore all
|
|
124
|
+
|
|
125
|
+
function buildRejectionOptions(env: HandlerEnv): RejectionOptions {
|
|
126
|
+
return {
|
|
127
|
+
allRejections: true,
|
|
128
|
+
onUnhandled(id: number, rejection: unknown): void {
|
|
129
|
+
if (captureEnabled && markReported(rejection)) {
|
|
130
|
+
reportHandled(rejection);
|
|
131
|
+
}
|
|
132
|
+
if (env.isDev) {
|
|
133
|
+
env.rnDevRejectionOptions()?.onUnhandled?.(id, rejection);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
onHandled(id: number): void {
|
|
137
|
+
if (env.isDev) {
|
|
138
|
+
env.rnDevRejectionOptions()?.onHandled?.(id);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function installRejectionTracker(env: HandlerEnv): void {
|
|
145
|
+
const options = buildRejectionOptions(env);
|
|
146
|
+
const hermes = env.enableHermesTracker();
|
|
147
|
+
if (hermes !== undefined) {
|
|
148
|
+
hermes(options);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const promiseLib = env.enablePromiseLibraryTracker();
|
|
152
|
+
if (promiseLib !== undefined) {
|
|
153
|
+
promiseLib(options);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function installErrorUtils(env: HandlerEnv): void {
|
|
158
|
+
const utils = env.errorUtils();
|
|
159
|
+
if (utils === undefined) {
|
|
160
|
+
warnNoErrorUtilsOnce();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const previous = utils.getGlobalHandler();
|
|
165
|
+
|
|
166
|
+
const onError = (error: unknown, isFatal?: boolean): void => {
|
|
167
|
+
let previousRan = false;
|
|
168
|
+
const runPrevious = (): void => {
|
|
169
|
+
// Stryker disable next-line ConditionalExpression,BooleanLiteral -- double-call guard; a single finally cannot observe a second entry
|
|
170
|
+
if (previousRan) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
// Stryker disable next-line BooleanLiteral -- paired with the guard above
|
|
174
|
+
previousRan = true;
|
|
175
|
+
previous(error, isFatal);
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
if (captureEnabled && markReported(error)) {
|
|
180
|
+
if (isFatal === true) {
|
|
181
|
+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
|
|
182
|
+
const timeout = new Promise<void>((resolve) => {
|
|
183
|
+
timeoutId = setTimeout(resolve, unhandledReportWaitMs());
|
|
184
|
+
});
|
|
185
|
+
void Promise.race([
|
|
186
|
+
Promise.resolve(reportUnhandled(error)).then(
|
|
187
|
+
() => undefined,
|
|
188
|
+
() => undefined,
|
|
189
|
+
),
|
|
190
|
+
timeout,
|
|
191
|
+
]).finally(() => {
|
|
192
|
+
// Stryker disable all -- clearTimeout is unobservable in unit tests; emptying this finally body except runPrevious is equivalent under the suite
|
|
193
|
+
if (timeoutId !== undefined) {
|
|
194
|
+
clearTimeout(timeoutId);
|
|
195
|
+
}
|
|
196
|
+
// Stryker restore all
|
|
197
|
+
runPrevious();
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
reportHandled(error);
|
|
202
|
+
}
|
|
203
|
+
} catch {
|
|
204
|
+
warnHandlerFailureOnce();
|
|
205
|
+
}
|
|
206
|
+
runPrevious();
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
utils.setGlobalHandler(onError);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Idempotent per JS runtime. Each half is marked installed only after it
|
|
214
|
+
* returns, so a throw leaves that half retryable and does not re-wrap the
|
|
215
|
+
* half that already succeeded.
|
|
216
|
+
*/
|
|
217
|
+
export function installExceptionHandlers(env: HandlerEnv = defaultEnv()): void {
|
|
218
|
+
if (!errorUtilsInstalled) {
|
|
219
|
+
installErrorUtils(env);
|
|
220
|
+
errorUtilsInstalled = true;
|
|
221
|
+
}
|
|
222
|
+
if (!rejectionTrackerInstalled) {
|
|
223
|
+
installRejectionTracker(env);
|
|
224
|
+
rejectionTrackerInstalled = true;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** R7: false only when the launch options set com.bugsee.option.detect.crash to false. */
|
|
229
|
+
export function setExceptionCaptureEnabled(enabled: boolean): void {
|
|
230
|
+
captureEnabled = enabled;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** Current R7 capture flag; `RootErrorReporter` reads this rather than copying it. */
|
|
234
|
+
export function isExceptionCaptureEnabled(): boolean {
|
|
235
|
+
return captureEnabled;
|
|
236
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { errorName } from '../errorName';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for a handled JS exception (`Bugsee.logException`).
|
|
5
|
+
*
|
|
6
|
+
* Encoded as JSON text for the TurboModule: `{domain?}` or `null` when nothing
|
|
7
|
+
* was set. Labels are set on the report through `setReportHandler`; the native
|
|
8
|
+
* SDKs take no per-call labels or `includeVideo`. Unknown keys are rejected; messages name the
|
|
9
|
+
* field and never the rejected value.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface ExceptionOptions {
|
|
13
|
+
/** The exception domain. Android groups issues by it; iOS records it with the report. Non-empty, at most 256 characters. */
|
|
14
|
+
domain?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const EXCEPTION_DOMAIN_MAX_LENGTH = 256;
|
|
18
|
+
|
|
19
|
+
const ALLOWED_KEYS = new Set(['domain']);
|
|
20
|
+
|
|
21
|
+
/** Every error `encodeExceptionOptions` threw: by identity, not by text. */
|
|
22
|
+
const thrownHere = new WeakSet<Error>();
|
|
23
|
+
|
|
24
|
+
function refuse(error: Error): never {
|
|
25
|
+
thrownHere.add(error);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* What a log line may say about `cause`: the message of an error
|
|
31
|
+
* `encodeExceptionOptions` threw -- this package's own validation text, which
|
|
32
|
+
* names fields and never values (`scripts/raw-messages.ts` checks every one
|
|
33
|
+
* of them) -- and only the class name of anything else. Never throws.
|
|
34
|
+
*/
|
|
35
|
+
export function exceptionOptionsMessage(cause: unknown): string {
|
|
36
|
+
// WeakSet.has, not instanceof: it never runs app code (a Proxy trap), never
|
|
37
|
+
// throws, and is false for a primitive, so this is safe inside the catch
|
|
38
|
+
// that calls it. A member is one of this file's own TypeError/RangeError
|
|
39
|
+
// instances, whose `message` is a plain data property.
|
|
40
|
+
return thrownHere.has(cause as Error) ? (cause as Error).message : errorName(cause);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* TypeError or RangeError naming the field and never its value; null for
|
|
45
|
+
* undefined or {}.
|
|
46
|
+
*/
|
|
47
|
+
export function encodeExceptionOptions(
|
|
48
|
+
options: ExceptionOptions | undefined,
|
|
49
|
+
): string | null {
|
|
50
|
+
if (options === undefined) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
54
|
+
refuse(new TypeError('ExceptionOptions must be a plain object'));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const record = options as Record<string, unknown>;
|
|
58
|
+
for (const key of Object.keys(record)) {
|
|
59
|
+
if (!ALLOWED_KEYS.has(key)) {
|
|
60
|
+
refuse(new TypeError(`ExceptionOptions has unknown key "${key}"`));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const out: Record<string, unknown> = {};
|
|
65
|
+
|
|
66
|
+
if (record.domain !== undefined) {
|
|
67
|
+
if (typeof record.domain !== 'string') {
|
|
68
|
+
refuse(new TypeError('ExceptionOptions.domain must be a string'));
|
|
69
|
+
}
|
|
70
|
+
if (record.domain.length === 0) {
|
|
71
|
+
refuse(new RangeError('ExceptionOptions.domain must be non-empty'));
|
|
72
|
+
}
|
|
73
|
+
if (record.domain.length > EXCEPTION_DOMAIN_MAX_LENGTH) {
|
|
74
|
+
refuse(new RangeError(
|
|
75
|
+
`ExceptionOptions.domain must be at most ${EXCEPTION_DOMAIN_MAX_LENGTH} characters`,
|
|
76
|
+
));
|
|
77
|
+
}
|
|
78
|
+
out.domain = record.domain;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (Object.keys(out).length === 0) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return JSON.stringify(out);
|
|
85
|
+
}
|