@flare-engine/errors 0.3.1 → 0.4.1

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/README.md CHANGED
@@ -34,6 +34,57 @@ const transport = composeTransports(
34
34
  </ErrorBoundary>
35
35
  ```
36
36
 
37
+ `createSentryTransport` starts Sentry with the SDK's own capture switched off — no global error or
38
+ rejection handlers, no automatic session tracking, no native crash handling, no console/network
39
+ instrumentation — so Sentry sends only what the transport is given, and a consent check placed in
40
+ front of the transport holds. Process-wide JS errors reach it through `installGlobalErrorCapture`
41
+ (next section). The one exception the transport cannot close: on Android 11+ the native SDK reports
42
+ past ANRs on its own; if consent must cover those, set the `io.sentry.anr.enable` meta-data to
43
+ `false` in your Android manifest ([Sentry Android docs](https://docs.sentry.io/platforms/android/configuration/app-not-respond/)).
44
+
45
+ ## Catching what the boundary cannot
46
+
47
+ `ErrorBoundary` only sees errors thrown during React's render phase. Most of a game's crashes are
48
+ not there — they are in the update loop, in an asset load, in a promise nobody awaited.
49
+ `installGlobalErrorCapture` routes those into the same transport chain.
50
+
51
+ ```ts
52
+ import { installGlobalErrorCapture, createConsoleTransport } from '@flare-engine/errors';
53
+
54
+ // `globalThis` supplies `addEventListener` on web and `ErrorUtils` on React
55
+ // Native, so one call covers both.
56
+ const capture = installGlobalErrorCapture(globalThis, {
57
+ transport: createConsoleTransport(),
58
+ context: { build: '1.2.3' },
59
+ });
60
+
61
+ // Later, e.g. on scene teardown or hot reload:
62
+ capture.uninstall();
63
+ ```
64
+
65
+ The transport can attach **after** installing. Errors raised in between are held in a small ring
66
+ buffer (default 20, oldest dropped) and drained on attach, so the crashes that happen during boot —
67
+ usually the interesting ones — are not lost while your reporter is still initialising:
68
+
69
+ ```ts
70
+ import { installGlobalErrorCapture, createClientTransport } from '@flare-engine/errors';
71
+
72
+ declare const Sentry: { captureException(error: unknown, hint?: unknown): unknown };
73
+
74
+ const capture = installGlobalErrorCapture(globalThis); // no transport yet
75
+ // ... boot, read config, initialise the reporter ...
76
+ capture.setTransport(createClientTransport(Sentry)); // buffered errors drain here
77
+ ```
78
+
79
+ Two things worth knowing:
80
+
81
+ - On React Native the previous `ErrorUtils` handler is **chained, not replaced** — that handler is
82
+ what shows the red box in development and ends the process on a fatal, so it still runs.
83
+ `uninstall()` restores it.
84
+ - `createSentryTransport` is native-only (it imports `@sentry/react-native`).
85
+ `createClientTransport` is the web counterpart: you initialise a browser client and inject it, so
86
+ this package depends on no reporter of its own.
87
+
37
88
  See [API spec](https://github.com/grzott/flare-engine/blob/main/docs/design/api-specs.md#flare-engineerrors--2kb-raw).
38
89
 
39
90
  ## License
package/dist/index.d.mts CHANGED
@@ -69,6 +69,106 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryS
69
69
  render(): ReactNode;
70
70
  }
71
71
  //#endregion
72
+ //#region src/global-capture.d.ts
73
+ /**
74
+ * React Native's `global.ErrorUtils`, described structurally so this package
75
+ * needs no React Native dependency or types.
76
+ */
77
+ interface ErrorUtilsLike {
78
+ getGlobalHandler?(): ((error: unknown, isFatal?: boolean) => void) | undefined;
79
+ setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;
80
+ }
81
+ /**
82
+ * What `installGlobalErrorCapture` needs from a global object.
83
+ *
84
+ * Both members are optional and independent, so one call handles either
85
+ * platform: on web `globalThis` supplies `addEventListener`, on React Native it
86
+ * supplies `ErrorUtils`, and in a test you pass a hand-built fake. Nothing here
87
+ * references `window`, `document` or any RN type.
88
+ */
89
+ interface GlobalErrorTarget {
90
+ addEventListener?(type: string, listener: (event: unknown) => void): void;
91
+ removeEventListener?(type: string, listener: (event: unknown) => void): void;
92
+ ErrorUtils?: ErrorUtilsLike;
93
+ }
94
+ /** Options for `installGlobalErrorCapture`. */
95
+ interface GlobalCaptureOptions {
96
+ /**
97
+ * Where captured errors go. May be omitted at install and attached later with
98
+ * `setTransport` — errors raised in between are held in the buffer below
99
+ * rather than dropped.
100
+ */
101
+ transport?: CrashTransport;
102
+ /**
103
+ * How many pre-transport errors to retain. Default 20. The oldest is dropped
104
+ * once full: a boot loop should not grow memory without bound, and the first
105
+ * errors are the ones worth keeping.
106
+ */
107
+ bufferSize?: number;
108
+ /** Context merged into every payload this capture produces. */
109
+ context?: Record<string, unknown>;
110
+ }
111
+ /** Handle returned by `installGlobalErrorCapture`. */
112
+ interface GlobalCaptureHandle {
113
+ /**
114
+ * Detach every handler this call installed and restore whatever was there
115
+ * before. Safe to call more than once.
116
+ */
117
+ uninstall(): void;
118
+ /** Attach or replace the transport, draining any buffered errors into it. */
119
+ setTransport(transport: CrashTransport): void;
120
+ /** How many errors are currently held awaiting a transport. */
121
+ readonly buffered: number;
122
+ }
123
+ /**
124
+ * Route uncaught errors and unhandled rejections into a `CrashTransport`.
125
+ *
126
+ * `ErrorBoundary` only sees errors thrown during React's render phase. The
127
+ * majority of a game's crashes are not there — they are in the update loop, in
128
+ * an asset load, in a promise nobody awaited — and before this nothing carried
129
+ * them to a transport.
130
+ *
131
+ * Both platforms are handled through the same call:
132
+ *
133
+ * ```ts
134
+ * const capture = installGlobalErrorCapture(globalThis, { transport });
135
+ * // ...
136
+ * capture.uninstall();
137
+ * ```
138
+ *
139
+ * The React Native handler is **chained, not replaced**: whatever handler was
140
+ * installed before still runs, because on RN that handler is what shows the
141
+ * red box in dev and terminates the app on a fatal. Swallowing it would convert
142
+ * a visible crash into a silent one.
143
+ */
144
+ declare function installGlobalErrorCapture(target: GlobalErrorTarget, options?: GlobalCaptureOptions): GlobalCaptureHandle;
145
+ /**
146
+ * A Sentry-browser-shaped client, described structurally so this package takes
147
+ * no dependency on `@sentry/browser` (or on any particular client).
148
+ */
149
+ interface ErrorClientLike {
150
+ captureException(error: unknown, hint?: unknown): unknown;
151
+ }
152
+ /**
153
+ * Transport over an injected browser error client.
154
+ *
155
+ * `createSentryTransport` is native-only — it dynamically imports
156
+ * `@sentry/react-native`, which does not resolve on web. This is the web half:
157
+ * the caller supplies an already-initialised client, so this package neither
158
+ * imports nor initialises one.
159
+ *
160
+ * ```ts
161
+ * import * as Sentry from '@sentry/browser';
162
+ * Sentry.init({ dsn });
163
+ * const transport = createClientTransport(Sentry);
164
+ * ```
165
+ *
166
+ * The payload is rebuilt into an `Error` because that is what such clients
167
+ * group by; the original stack is preserved rather than replaced with this
168
+ * function's own.
169
+ */
170
+ declare function createClientTransport(client: ErrorClientLike): CrashTransport;
171
+ //#endregion
72
172
  //#region src/transports/sentry.d.ts
73
173
  interface SentryTransportOptions {
74
174
  dsn?: string;
@@ -79,5 +179,5 @@ interface SentryTransportOptions {
79
179
  }
80
180
  declare function createSentryTransport(opts: SentryTransportOptions): CrashTransport;
81
181
  //#endregion
82
- export { type CrashPayload, type CrashTransport, ErrorBoundary, type ErrorBoundaryProps, type SentryTransportOptions, composeTransports, createConsoleTransport, createCrashPayload, createNoopTransport, createSentryTransport };
182
+ export { type CrashPayload, type CrashTransport, ErrorBoundary, type ErrorBoundaryProps, type ErrorClientLike, type ErrorUtilsLike, type GlobalCaptureHandle, type GlobalCaptureOptions, type GlobalErrorTarget, type SentryTransportOptions, composeTransports, createClientTransport, createConsoleTransport, createCrashPayload, createNoopTransport, createSentryTransport, installGlobalErrorCapture };
83
183
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/crash-payload.ts","../src/transport.ts","../src/compose.ts","../src/error-boundary.tsx","../src/transports/sentry.ts"],"mappings":";;;;;;UAIiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,SAAS;;;;;;iBAOK,mBACd,gBACA,UAAS,0BACR;;;;;;;UClBc;EACf,OAAO,SAAS,sBAAsB;;;iBAIxB,uBAAuB;;;;;iBAYvB,0BAA0B;;;iBCrB1B,qBAAqB,YAAY,mBAAmB;;;UCEnD;EACf,UAAU;;EAEV,WAAW,SAAS,cAAc,sBAAsB;;EAExD,YAAY;;EAEZ,UAAU;;EAEV,WAAW,gBAAgB,SAAS;;UAG5B;EACR,SAAS;;;;;;;cAQE,sBAAsB,UAAU,oBAAoB;EAC/D,OAAO;SAEA,yBAAyB,iBAAiB;EAIjD,kBAAkB,gBAAgB,MAAM;EAWxC;EAIA,UAAU;;;;UC3CK;EACf;EACA;EACA;EACA;EACA;;iBAGc,sBAAsB,MAAM,yBAAyB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/crash-payload.ts","../src/transport.ts","../src/compose.ts","../src/error-boundary.tsx","../src/global-capture.ts","../src/transports/sentry.ts"],"mappings":";;;;;;UAIiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,SAAS;;;;;;iBAOK,mBACd,gBACA,UAAS,0BACR;;;;;;;UClBc;EACf,OAAO,SAAS,sBAAsB;;;iBAIxB,uBAAuB;;;;;iBAYvB,0BAA0B;;;iBCrB1B,qBAAqB,YAAY,mBAAmB;;;UCEnD;EACf,UAAU;;EAEV,WAAW,SAAS,cAAc,sBAAsB;;EAExD,YAAY;;EAEZ,UAAU;;EAEV,WAAW,gBAAgB,SAAS;;UAG5B;EACR,SAAS;;;;;;;cAQE,sBAAsB,UAAU,oBAAoB;EAC/D,OAAO;SAEA,yBAAyB,iBAAiB;EAIjD,kBAAkB,gBAAgB,MAAM;EAWxC;EAIA,UAAU;;;;;;;;UCxCK;EACf,uBAAuB,gBAAgB;EACvC,iBAAiB,UAAU,gBAAgB;;;;;;;;;;UAW5B;EACf,kBAAkB,cAAc,WAAW;EAC3C,qBAAqB,cAAc,WAAW;EAC9C,aAAa;;;UAIE;;;;;;EAMf,YAAY;;;;;;EAMZ;;EAEA,UAAU;;;UAIK;;;;;EAKf;;EAEA,aAAa,WAAW;;WAEf;;;;;;;;;;;;;;;;;;;;;;;iBAqCK,0BACd,QAAQ,mBACR,UAAU,uBACT;;;;;UAgFc;EACf,iBAAiB,gBAAgB;;;;;;;;;;;;;;;;;;;;iBAqBnB,sBAAsB,QAAQ,kBAAkB;;;UC/L/C;EACf;EACA;EACA;EACA;EACA;;iBAyBc,sBAAsB,MAAM,yBAAyB"}
package/dist/index.d.ts CHANGED
@@ -69,6 +69,106 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryS
69
69
  render(): ReactNode;
70
70
  }
71
71
  //#endregion
72
+ //#region src/global-capture.d.ts
73
+ /**
74
+ * React Native's `global.ErrorUtils`, described structurally so this package
75
+ * needs no React Native dependency or types.
76
+ */
77
+ interface ErrorUtilsLike {
78
+ getGlobalHandler?(): ((error: unknown, isFatal?: boolean) => void) | undefined;
79
+ setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;
80
+ }
81
+ /**
82
+ * What `installGlobalErrorCapture` needs from a global object.
83
+ *
84
+ * Both members are optional and independent, so one call handles either
85
+ * platform: on web `globalThis` supplies `addEventListener`, on React Native it
86
+ * supplies `ErrorUtils`, and in a test you pass a hand-built fake. Nothing here
87
+ * references `window`, `document` or any RN type.
88
+ */
89
+ interface GlobalErrorTarget {
90
+ addEventListener?(type: string, listener: (event: unknown) => void): void;
91
+ removeEventListener?(type: string, listener: (event: unknown) => void): void;
92
+ ErrorUtils?: ErrorUtilsLike;
93
+ }
94
+ /** Options for `installGlobalErrorCapture`. */
95
+ interface GlobalCaptureOptions {
96
+ /**
97
+ * Where captured errors go. May be omitted at install and attached later with
98
+ * `setTransport` — errors raised in between are held in the buffer below
99
+ * rather than dropped.
100
+ */
101
+ transport?: CrashTransport;
102
+ /**
103
+ * How many pre-transport errors to retain. Default 20. The oldest is dropped
104
+ * once full: a boot loop should not grow memory without bound, and the first
105
+ * errors are the ones worth keeping.
106
+ */
107
+ bufferSize?: number;
108
+ /** Context merged into every payload this capture produces. */
109
+ context?: Record<string, unknown>;
110
+ }
111
+ /** Handle returned by `installGlobalErrorCapture`. */
112
+ interface GlobalCaptureHandle {
113
+ /**
114
+ * Detach every handler this call installed and restore whatever was there
115
+ * before. Safe to call more than once.
116
+ */
117
+ uninstall(): void;
118
+ /** Attach or replace the transport, draining any buffered errors into it. */
119
+ setTransport(transport: CrashTransport): void;
120
+ /** How many errors are currently held awaiting a transport. */
121
+ readonly buffered: number;
122
+ }
123
+ /**
124
+ * Route uncaught errors and unhandled rejections into a `CrashTransport`.
125
+ *
126
+ * `ErrorBoundary` only sees errors thrown during React's render phase. The
127
+ * majority of a game's crashes are not there — they are in the update loop, in
128
+ * an asset load, in a promise nobody awaited — and before this nothing carried
129
+ * them to a transport.
130
+ *
131
+ * Both platforms are handled through the same call:
132
+ *
133
+ * ```ts
134
+ * const capture = installGlobalErrorCapture(globalThis, { transport });
135
+ * // ...
136
+ * capture.uninstall();
137
+ * ```
138
+ *
139
+ * The React Native handler is **chained, not replaced**: whatever handler was
140
+ * installed before still runs, because on RN that handler is what shows the
141
+ * red box in dev and terminates the app on a fatal. Swallowing it would convert
142
+ * a visible crash into a silent one.
143
+ */
144
+ declare function installGlobalErrorCapture(target: GlobalErrorTarget, options?: GlobalCaptureOptions): GlobalCaptureHandle;
145
+ /**
146
+ * A Sentry-browser-shaped client, described structurally so this package takes
147
+ * no dependency on `@sentry/browser` (or on any particular client).
148
+ */
149
+ interface ErrorClientLike {
150
+ captureException(error: unknown, hint?: unknown): unknown;
151
+ }
152
+ /**
153
+ * Transport over an injected browser error client.
154
+ *
155
+ * `createSentryTransport` is native-only — it dynamically imports
156
+ * `@sentry/react-native`, which does not resolve on web. This is the web half:
157
+ * the caller supplies an already-initialised client, so this package neither
158
+ * imports nor initialises one.
159
+ *
160
+ * ```ts
161
+ * import * as Sentry from '@sentry/browser';
162
+ * Sentry.init({ dsn });
163
+ * const transport = createClientTransport(Sentry);
164
+ * ```
165
+ *
166
+ * The payload is rebuilt into an `Error` because that is what such clients
167
+ * group by; the original stack is preserved rather than replaced with this
168
+ * function's own.
169
+ */
170
+ declare function createClientTransport(client: ErrorClientLike): CrashTransport;
171
+ //#endregion
72
172
  //#region src/transports/sentry.d.ts
73
173
  interface SentryTransportOptions {
74
174
  dsn?: string;
@@ -79,5 +179,5 @@ interface SentryTransportOptions {
79
179
  }
80
180
  declare function createSentryTransport(opts: SentryTransportOptions): CrashTransport;
81
181
  //#endregion
82
- export { type CrashPayload, type CrashTransport, ErrorBoundary, type ErrorBoundaryProps, type SentryTransportOptions, composeTransports, createConsoleTransport, createCrashPayload, createNoopTransport, createSentryTransport };
182
+ export { type CrashPayload, type CrashTransport, ErrorBoundary, type ErrorBoundaryProps, type ErrorClientLike, type ErrorUtilsLike, type GlobalCaptureHandle, type GlobalCaptureOptions, type GlobalErrorTarget, type SentryTransportOptions, composeTransports, createClientTransport, createConsoleTransport, createCrashPayload, createNoopTransport, createSentryTransport, installGlobalErrorCapture };
83
183
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/crash-payload.ts","../src/transport.ts","../src/compose.ts","../src/error-boundary.tsx","../src/transports/sentry.ts"],"mappings":";;;;;;UAIiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,SAAS;;;;;;iBAOK,mBACd,gBACA,UAAS,0BACR;;;;;;;UClBc;EACf,OAAO,SAAS,sBAAsB;;;iBAIxB,uBAAuB;;;;;iBAYvB,0BAA0B;;;iBCrB1B,qBAAqB,YAAY,mBAAmB;;;UCEnD;EACf,UAAU;;EAEV,WAAW,SAAS,cAAc,sBAAsB;;EAExD,YAAY;;EAEZ,UAAU;;EAEV,WAAW,gBAAgB,SAAS;;UAG5B;EACR,SAAS;;;;;;;cAQE,sBAAsB,UAAU,oBAAoB;EAC/D,OAAO;SAEA,yBAAyB,iBAAiB;EAIjD,kBAAkB,gBAAgB,MAAM;EAWxC;EAIA,UAAU;;;;UC3CK;EACf;EACA;EACA;EACA;EACA;;iBAGc,sBAAsB,MAAM,yBAAyB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/crash-payload.ts","../src/transport.ts","../src/compose.ts","../src/error-boundary.tsx","../src/global-capture.ts","../src/transports/sentry.ts"],"mappings":";;;;;;UAIiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA,SAAS;;;;;;iBAOK,mBACd,gBACA,UAAS,0BACR;;;;;;;UClBc;EACf,OAAO,SAAS,sBAAsB;;;iBAIxB,uBAAuB;;;;;iBAYvB,0BAA0B;;;iBCrB1B,qBAAqB,YAAY,mBAAmB;;;UCEnD;EACf,UAAU;;EAEV,WAAW,SAAS,cAAc,sBAAsB;;EAExD,YAAY;;EAEZ,UAAU;;EAEV,WAAW,gBAAgB,SAAS;;UAG5B;EACR,SAAS;;;;;;;cAQE,sBAAsB,UAAU,oBAAoB;EAC/D,OAAO;SAEA,yBAAyB,iBAAiB;EAIjD,kBAAkB,gBAAgB,MAAM;EAWxC;EAIA,UAAU;;;;;;;;UCxCK;EACf,uBAAuB,gBAAgB;EACvC,iBAAiB,UAAU,gBAAgB;;;;;;;;;;UAW5B;EACf,kBAAkB,cAAc,WAAW;EAC3C,qBAAqB,cAAc,WAAW;EAC9C,aAAa;;;UAIE;;;;;;EAMf,YAAY;;;;;;EAMZ;;EAEA,UAAU;;;UAIK;;;;;EAKf;;EAEA,aAAa,WAAW;;WAEf;;;;;;;;;;;;;;;;;;;;;;;iBAqCK,0BACd,QAAQ,mBACR,UAAU,uBACT;;;;;UAgFc;EACf,iBAAiB,gBAAgB;;;;;;;;;;;;;;;;;;;;iBAqBnB,sBAAsB,QAAQ,kBAAkB;;;UC/L/C;EACf;EACA;EACA;EACA;EACA;;iBAyBc,sBAAsB,MAAM,yBAAyB"}
package/dist/index.js CHANGED
@@ -75,6 +75,137 @@ var ErrorBoundary = class extends react.Component {
75
75
  }
76
76
  };
77
77
  //#endregion
78
+ //#region src/global-capture.ts
79
+ /** Pull the underlying error out of a structurally-typed DOM-ish event. */
80
+ function unwrapEvent(event, key) {
81
+ if (typeof event === "object" && event !== null && key in event) {
82
+ const value = event[key];
83
+ if (value !== void 0 && value !== null) return value;
84
+ }
85
+ if (typeof event === "object" && event !== null && "message" in event) return event.message;
86
+ return event;
87
+ }
88
+ /**
89
+ * Route uncaught errors and unhandled rejections into a `CrashTransport`.
90
+ *
91
+ * `ErrorBoundary` only sees errors thrown during React's render phase. The
92
+ * majority of a game's crashes are not there — they are in the update loop, in
93
+ * an asset load, in a promise nobody awaited — and before this nothing carried
94
+ * them to a transport.
95
+ *
96
+ * Both platforms are handled through the same call:
97
+ *
98
+ * ```ts
99
+ * const capture = installGlobalErrorCapture(globalThis, { transport });
100
+ * // ...
101
+ * capture.uninstall();
102
+ * ```
103
+ *
104
+ * The React Native handler is **chained, not replaced**: whatever handler was
105
+ * installed before still runs, because on RN that handler is what shows the
106
+ * red box in dev and terminates the app on a fatal. Swallowing it would convert
107
+ * a visible crash into a silent one.
108
+ */
109
+ function installGlobalErrorCapture(target, options) {
110
+ const bufferSize = Math.max(0, options?.bufferSize ?? 20);
111
+ const context = options?.context ?? {};
112
+ let transport = options?.transport ?? null;
113
+ const pending = [];
114
+ let installed = true;
115
+ const emit = (error, extra) => {
116
+ const payload = createCrashPayload(error, extra ? {
117
+ ...context,
118
+ ...extra
119
+ } : { ...context });
120
+ if (transport === null) {
121
+ if (bufferSize === 0) return;
122
+ if (pending.length === bufferSize) pending.shift();
123
+ pending.push(payload);
124
+ return;
125
+ }
126
+ try {
127
+ transport.report(payload);
128
+ } catch (err) {
129
+ console.error("[@flare-engine/errors] transport threw while reporting", err);
130
+ }
131
+ };
132
+ const onError = (event) => {
133
+ emit(unwrapEvent(event, "error"), { source: "error" });
134
+ };
135
+ const onRejection = (event) => {
136
+ emit(unwrapEvent(event, "reason"), { source: "unhandledrejection" });
137
+ };
138
+ const canListen = typeof target.addEventListener === "function" && typeof target.removeEventListener === "function";
139
+ if (canListen) {
140
+ target.addEventListener?.("error", onError);
141
+ target.addEventListener?.("unhandledrejection", onRejection);
142
+ }
143
+ const errorUtils = target.ErrorUtils;
144
+ const previousHandler = errorUtils?.getGlobalHandler?.();
145
+ if (errorUtils !== void 0) errorUtils.setGlobalHandler((error, isFatal) => {
146
+ emit(error, {
147
+ source: "errorUtils",
148
+ isFatal: isFatal ?? false
149
+ });
150
+ previousHandler?.(error, isFatal);
151
+ });
152
+ return {
153
+ uninstall() {
154
+ if (!installed) return;
155
+ installed = false;
156
+ if (canListen) {
157
+ target.removeEventListener?.("error", onError);
158
+ target.removeEventListener?.("unhandledrejection", onRejection);
159
+ }
160
+ if (errorUtils !== void 0 && previousHandler !== void 0) errorUtils.setGlobalHandler(previousHandler);
161
+ },
162
+ setTransport(next) {
163
+ transport = next;
164
+ while (pending.length > 0) {
165
+ const payload = pending.shift();
166
+ try {
167
+ next.report(payload);
168
+ } catch (err) {
169
+ console.error("[@flare-engine/errors] transport threw while draining", err);
170
+ }
171
+ }
172
+ },
173
+ get buffered() {
174
+ return pending.length;
175
+ }
176
+ };
177
+ }
178
+ /**
179
+ * Transport over an injected browser error client.
180
+ *
181
+ * `createSentryTransport` is native-only — it dynamically imports
182
+ * `@sentry/react-native`, which does not resolve on web. This is the web half:
183
+ * the caller supplies an already-initialised client, so this package neither
184
+ * imports nor initialises one.
185
+ *
186
+ * ```ts
187
+ * import * as Sentry from '@sentry/browser';
188
+ * Sentry.init({ dsn });
189
+ * const transport = createClientTransport(Sentry);
190
+ * ```
191
+ *
192
+ * The payload is rebuilt into an `Error` because that is what such clients
193
+ * group by; the original stack is preserved rather than replaced with this
194
+ * function's own.
195
+ */
196
+ function createClientTransport(client) {
197
+ return { report(payload) {
198
+ const error = new Error(payload.message);
199
+ error.name = payload.name;
200
+ if (payload.stack !== null) error.stack = payload.stack;
201
+ try {
202
+ client.captureException(error, { extra: payload.context });
203
+ } catch (err) {
204
+ console.error("[@flare-engine/errors] client.captureException threw", err);
205
+ }
206
+ } };
207
+ }
208
+ //#endregion
78
209
  //#region src/transport.ts
79
210
  /** Transport that discards every payload. The default. */
80
211
  function createNoopTransport() {
@@ -91,6 +222,19 @@ function createConsoleTransport() {
91
222
  }
92
223
  //#endregion
93
224
  //#region src/transports/sentry.ts
225
+ const KEPT_INTEGRATIONS = /* @__PURE__ */ new Set([
226
+ "RewriteFrames",
227
+ "Release",
228
+ "DebugMeta",
229
+ "SdkInfo",
230
+ "Dedupe",
231
+ "InboundFilters",
232
+ "NativeLinkedErrors",
233
+ "EventOrigin"
234
+ ]);
235
+ function keepEventProcessors(defaults) {
236
+ return defaults.filter((integration) => KEPT_INTEGRATIONS.has(integration.name));
237
+ }
94
238
  function createSentryTransport(opts) {
95
239
  if (!opts.dsn || opts.enabled === false) return createNoopTransport();
96
240
  const dsn = opts.dsn;
@@ -104,7 +248,13 @@ function createSentryTransport(opts) {
104
248
  dsn,
105
249
  environment: opts.environment,
106
250
  release: opts.release,
107
- sampleRate: opts.sampleRate
251
+ sampleRate: opts.sampleRate,
252
+ integrations: keepEventProcessors,
253
+ enableAutoSessionTracking: false,
254
+ enableNativeCrashHandling: false,
255
+ enableAppHangTracking: false,
256
+ enableWatchdogTerminationTracking: false,
257
+ sendClientReports: false
108
258
  });
109
259
  } catch {
110
260
  console.error("[@flare-engine/errors] Failed to load @sentry/react-native — degrading to noop");
@@ -126,9 +276,11 @@ function createSentryTransport(opts) {
126
276
  //#endregion
127
277
  exports.ErrorBoundary = ErrorBoundary;
128
278
  exports.composeTransports = composeTransports;
279
+ exports.createClientTransport = createClientTransport;
129
280
  exports.createConsoleTransport = createConsoleTransport;
130
281
  exports.createCrashPayload = createCrashPayload;
131
282
  exports.createNoopTransport = createNoopTransport;
132
283
  exports.createSentryTransport = createSentryTransport;
284
+ exports.installGlobalErrorCapture = installGlobalErrorCapture;
133
285
 
134
286
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Component"],"sources":["../src/compose.ts","../src/crash-payload.ts","../src/error-boundary.tsx","../src/transport.ts","../src/transports/sentry.ts"],"sourcesContent":["import type { CrashTransport } from './transport.js';\n\nexport function composeTransports(...transports: CrashTransport[]): CrashTransport {\n return {\n async report(payload) {\n for (const t of transports) {\n try {\n await t.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] composeTransports: child transport threw', err);\n }\n }\n },\n };\n}\n","/**\n * Serializable crash payload. Everything here is JSON-safe so transports can\n * post it to Sentry / Crashlytics / a custom HTTP endpoint without extra work.\n */\nexport interface CrashPayload {\n /** Error message. */\n message: string;\n /** Error name (e.g., `TypeError`). */\n name: string;\n /** Captured stack trace, if available. */\n stack: string | null;\n /** Monotonic ms timestamp — `Date.now()` at capture. */\n timestamp: number;\n /** Optional free-form context supplied by the caller. */\n context: Record<string, unknown>;\n}\n\n/**\n * Capture an unknown thrown value as a serializable crash payload. Handles\n * `Error` instances, string throws, and arbitrary values.\n */\nexport function createCrashPayload(\n error: unknown,\n context: Record<string, unknown> = {},\n): CrashPayload {\n if (error instanceof Error) {\n return {\n message: error.message,\n name: error.name,\n stack: error.stack ?? null,\n timestamp: Date.now(),\n context,\n };\n }\n if (typeof error === 'string') {\n return { message: error, name: 'Error', stack: null, timestamp: Date.now(), context };\n }\n let message: string;\n try {\n message = JSON.stringify(error);\n } catch {\n message = String(error);\n }\n return { message, name: 'NonError', stack: null, timestamp: Date.now(), context };\n}\n","import { Component, type ErrorInfo, type ReactNode } from 'react';\nimport { type CrashPayload, createCrashPayload } from './crash-payload.js';\nimport type { CrashTransport } from './transport.js';\n\nexport interface ErrorBoundaryProps {\n children: ReactNode;\n /** Rendered when an error is caught. Receives the payload + a reset callback. */\n fallback: (payload: CrashPayload, reset: () => void) => ReactNode;\n /** Transport invoked once per caught error. */\n transport?: CrashTransport;\n /** Additional context merged into every payload captured by this boundary. */\n context?: Record<string, unknown>;\n /** Called with both the raw error and the payload for custom side effects. */\n onError?: (error: unknown, payload: CrashPayload) => void;\n}\n\ninterface ErrorBoundaryState {\n payload: CrashPayload | null;\n}\n\n/**\n * React error boundary that captures render-phase errors into a structured\n * `CrashPayload`, forwards it to an optional transport, and renders the\n * caller-supplied fallback.\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n state: ErrorBoundaryState = { payload: null };\n\n static getDerivedStateFromError(error: unknown): ErrorBoundaryState {\n return { payload: createCrashPayload(error) };\n }\n\n componentDidCatch(error: unknown, info: ErrorInfo): void {\n const context = {\n ...this.props.context,\n componentStack: info.componentStack ?? null,\n };\n const payload = createCrashPayload(error, context);\n this.setState({ payload });\n this.props.transport?.report(payload);\n this.props.onError?.(error, payload);\n }\n\n reset = (): void => {\n this.setState({ payload: null });\n };\n\n render(): ReactNode {\n if (this.state.payload !== null) {\n return this.props.fallback(this.state.payload, this.reset);\n }\n return this.props.children;\n }\n}\n","import type { CrashPayload } from './crash-payload.js';\n\n/**\n * Pluggable transport for reporting crashes. Implementations send the payload\n * wherever they need — Sentry, Crashlytics, an HTTP endpoint, or nowhere.\n */\nexport interface CrashTransport {\n report(payload: CrashPayload): void | Promise<void>;\n}\n\n/** Transport that discards every payload. The default. */\nexport function createNoopTransport(): CrashTransport {\n return {\n report() {\n /* no-op */\n },\n };\n}\n\n/**\n * Transport that logs payloads via `console.error`. Useful in development and\n * as a wrapper around another transport when debugging.\n */\nexport function createConsoleTransport(): CrashTransport {\n return {\n report(payload) {\n console.error('[@flare-engine/errors]', payload);\n },\n };\n}\n","import type { CrashPayload } from '../crash-payload.js';\nimport type { CrashTransport } from '../transport.js';\nimport { createNoopTransport } from '../transport.js';\n\nexport interface SentryTransportOptions {\n dsn?: string;\n environment?: string;\n release?: string;\n sampleRate?: number;\n enabled?: boolean;\n}\n\nexport function createSentryTransport(opts: SentryTransportOptions): CrashTransport {\n if (!opts.dsn || opts.enabled === false) {\n return createNoopTransport();\n }\n\n const dsn = opts.dsn;\n type SentryMod = typeof import('@sentry/react-native');\n let mod: SentryMod | null = null;\n let loadFailed = false;\n\n return {\n async report(payload: CrashPayload): Promise<void> {\n if (loadFailed) return;\n\n if (mod === null) {\n try {\n mod = await import('@sentry/react-native');\n mod.init({\n dsn,\n environment: opts.environment,\n release: opts.release,\n sampleRate: opts.sampleRate,\n });\n } catch {\n console.error(\n '[@flare-engine/errors] Failed to load @sentry/react-native — degrading to noop',\n );\n loadFailed = true;\n return;\n }\n }\n\n try {\n const err = Object.assign(new Error(payload.message), { name: payload.name });\n if (payload.stack !== null) err.stack = payload.stack;\n mod.captureException(err, {\n extra: { ...payload.context, capturedAt: payload.timestamp },\n });\n } catch {\n console.error('[@flare-engine/errors] Sentry captureException failed');\n }\n },\n };\n}\n"],"mappings":";;;AAEA,SAAgB,kBAAkB,GAAG,YAA8C;CACjF,OAAO,EACL,MAAM,OAAO,SAAS;EACpB,KAAK,MAAM,KAAK,YACd,IAAI;GACF,MAAM,EAAE,OAAO,OAAO;EACxB,SAAS,KAAK;GACZ,QAAQ,MAAM,mEAAmE,GAAG;EACtF;CAEJ,EACF;AACF;;;;;;;ACOA,SAAgB,mBACd,OACA,UAAmC,CAAC,GACtB;CACd,IAAI,iBAAiB,OACnB,OAAO;EACL,SAAS,MAAM;EACf,MAAM,MAAM;EACZ,OAAO,MAAM,SAAS;EACtB,WAAW,KAAK,IAAI;EACpB;CACF;CAEF,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE,SAAS;EAAO,MAAM;EAAS,OAAO;EAAM,WAAW,KAAK,IAAI;EAAG;CAAQ;CAEtF,IAAI;CACJ,IAAI;EACF,UAAU,KAAK,UAAU,KAAK;CAChC,QAAQ;EACN,UAAU,OAAO,KAAK;CACxB;CACA,OAAO;EAAE;EAAS,MAAM;EAAY,OAAO;EAAM,WAAW,KAAK,IAAI;EAAG;CAAQ;AAClF;;;;;;;;ACnBA,IAAa,gBAAb,cAAmCA,MAAAA,UAAkD;CACnF,QAA4B,EAAE,SAAS,KAAK;CAE5C,OAAO,yBAAyB,OAAoC;EAClE,OAAO,EAAE,SAAS,mBAAmB,KAAK,EAAE;CAC9C;CAEA,kBAAkB,OAAgB,MAAuB;EAKvD,MAAM,UAAU,mBAAmB,OAAO;GAHxC,GAAG,KAAK,MAAM;GACd,gBAAgB,KAAK,kBAAkB;EAEO,CAAC;EACjD,KAAK,SAAS,EAAE,QAAQ,CAAC;EACzB,KAAK,MAAM,WAAW,OAAO,OAAO;EACpC,KAAK,MAAM,UAAU,OAAO,OAAO;CACrC;CAEA,cAAoB;EAClB,KAAK,SAAS,EAAE,SAAS,KAAK,CAAC;CACjC;CAEA,SAAoB;EAClB,IAAI,KAAK,MAAM,YAAY,MACzB,OAAO,KAAK,MAAM,SAAS,KAAK,MAAM,SAAS,KAAK,KAAK;EAE3D,OAAO,KAAK,MAAM;CACpB;AACF;;;;AC1CA,SAAgB,sBAAsC;CACpD,OAAO,EACL,SAAS,CAET,EACF;AACF;;;;;AAMA,SAAgB,yBAAyC;CACvD,OAAO,EACL,OAAO,SAAS;EACd,QAAQ,MAAM,0BAA0B,OAAO;CACjD,EACF;AACF;;;ACjBA,SAAgB,sBAAsB,MAA8C;CAClF,IAAI,CAAC,KAAK,OAAO,KAAK,YAAY,OAChC,OAAO,oBAAoB;CAG7B,MAAM,MAAM,KAAK;CAEjB,IAAI,MAAwB;CAC5B,IAAI,aAAa;CAEjB,OAAO,EACL,MAAM,OAAO,SAAsC;EACjD,IAAI,YAAY;EAEhB,IAAI,QAAQ,MACV,IAAI;GACF,MAAM,MAAM,OAAO;GACnB,IAAI,KAAK;IACP;IACA,aAAa,KAAK;IAClB,SAAS,KAAK;IACd,YAAY,KAAK;GACnB,CAAC;EACH,QAAQ;GACN,QAAQ,MACN,gFACF;GACA,aAAa;GACb;EACF;EAGF,IAAI;GACF,MAAM,MAAM,OAAO,OAAO,IAAI,MAAM,QAAQ,OAAO,GAAG,EAAE,MAAM,QAAQ,KAAK,CAAC;GAC5E,IAAI,QAAQ,UAAU,MAAM,IAAI,QAAQ,QAAQ;GAChD,IAAI,iBAAiB,KAAK,EACxB,OAAO;IAAE,GAAG,QAAQ;IAAS,YAAY,QAAQ;GAAU,EAC7D,CAAC;EACH,QAAQ;GACN,QAAQ,MAAM,uDAAuD;EACvE;CACF,EACF;AACF"}
1
+ {"version":3,"file":"index.js","names":["Component"],"sources":["../src/compose.ts","../src/crash-payload.ts","../src/error-boundary.tsx","../src/global-capture.ts","../src/transport.ts","../src/transports/sentry.ts"],"sourcesContent":["import type { CrashTransport } from './transport.js';\n\nexport function composeTransports(...transports: CrashTransport[]): CrashTransport {\n return {\n async report(payload) {\n for (const t of transports) {\n try {\n await t.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] composeTransports: child transport threw', err);\n }\n }\n },\n };\n}\n","/**\n * Serializable crash payload. Everything here is JSON-safe so transports can\n * post it to Sentry / Crashlytics / a custom HTTP endpoint without extra work.\n */\nexport interface CrashPayload {\n /** Error message. */\n message: string;\n /** Error name (e.g., `TypeError`). */\n name: string;\n /** Captured stack trace, if available. */\n stack: string | null;\n /** Monotonic ms timestamp — `Date.now()` at capture. */\n timestamp: number;\n /** Optional free-form context supplied by the caller. */\n context: Record<string, unknown>;\n}\n\n/**\n * Capture an unknown thrown value as a serializable crash payload. Handles\n * `Error` instances, string throws, and arbitrary values.\n */\nexport function createCrashPayload(\n error: unknown,\n context: Record<string, unknown> = {},\n): CrashPayload {\n if (error instanceof Error) {\n return {\n message: error.message,\n name: error.name,\n stack: error.stack ?? null,\n timestamp: Date.now(),\n context,\n };\n }\n if (typeof error === 'string') {\n return { message: error, name: 'Error', stack: null, timestamp: Date.now(), context };\n }\n let message: string;\n try {\n message = JSON.stringify(error);\n } catch {\n message = String(error);\n }\n return { message, name: 'NonError', stack: null, timestamp: Date.now(), context };\n}\n","import { Component, type ErrorInfo, type ReactNode } from 'react';\nimport { type CrashPayload, createCrashPayload } from './crash-payload.js';\nimport type { CrashTransport } from './transport.js';\n\nexport interface ErrorBoundaryProps {\n children: ReactNode;\n /** Rendered when an error is caught. Receives the payload + a reset callback. */\n fallback: (payload: CrashPayload, reset: () => void) => ReactNode;\n /** Transport invoked once per caught error. */\n transport?: CrashTransport;\n /** Additional context merged into every payload captured by this boundary. */\n context?: Record<string, unknown>;\n /** Called with both the raw error and the payload for custom side effects. */\n onError?: (error: unknown, payload: CrashPayload) => void;\n}\n\ninterface ErrorBoundaryState {\n payload: CrashPayload | null;\n}\n\n/**\n * React error boundary that captures render-phase errors into a structured\n * `CrashPayload`, forwards it to an optional transport, and renders the\n * caller-supplied fallback.\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n state: ErrorBoundaryState = { payload: null };\n\n static getDerivedStateFromError(error: unknown): ErrorBoundaryState {\n return { payload: createCrashPayload(error) };\n }\n\n componentDidCatch(error: unknown, info: ErrorInfo): void {\n const context = {\n ...this.props.context,\n componentStack: info.componentStack ?? null,\n };\n const payload = createCrashPayload(error, context);\n this.setState({ payload });\n this.props.transport?.report(payload);\n this.props.onError?.(error, payload);\n }\n\n reset = (): void => {\n this.setState({ payload: null });\n };\n\n render(): ReactNode {\n if (this.state.payload !== null) {\n return this.props.fallback(this.state.payload, this.reset);\n }\n return this.props.children;\n }\n}\n","import { createCrashPayload } from './crash-payload.js';\nimport type { CrashTransport } from './transport.js';\n\n/**\n * React Native's `global.ErrorUtils`, described structurally so this package\n * needs no React Native dependency or types.\n */\nexport interface ErrorUtilsLike {\n getGlobalHandler?(): ((error: unknown, isFatal?: boolean) => void) | undefined;\n setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;\n}\n\n/**\n * What `installGlobalErrorCapture` needs from a global object.\n *\n * Both members are optional and independent, so one call handles either\n * platform: on web `globalThis` supplies `addEventListener`, on React Native it\n * supplies `ErrorUtils`, and in a test you pass a hand-built fake. Nothing here\n * references `window`, `document` or any RN type.\n */\nexport interface GlobalErrorTarget {\n addEventListener?(type: string, listener: (event: unknown) => void): void;\n removeEventListener?(type: string, listener: (event: unknown) => void): void;\n ErrorUtils?: ErrorUtilsLike;\n}\n\n/** Options for `installGlobalErrorCapture`. */\nexport interface GlobalCaptureOptions {\n /**\n * Where captured errors go. May be omitted at install and attached later with\n * `setTransport` — errors raised in between are held in the buffer below\n * rather than dropped.\n */\n transport?: CrashTransport;\n /**\n * How many pre-transport errors to retain. Default 20. The oldest is dropped\n * once full: a boot loop should not grow memory without bound, and the first\n * errors are the ones worth keeping.\n */\n bufferSize?: number;\n /** Context merged into every payload this capture produces. */\n context?: Record<string, unknown>;\n}\n\n/** Handle returned by `installGlobalErrorCapture`. */\nexport interface GlobalCaptureHandle {\n /**\n * Detach every handler this call installed and restore whatever was there\n * before. Safe to call more than once.\n */\n uninstall(): void;\n /** Attach or replace the transport, draining any buffered errors into it. */\n setTransport(transport: CrashTransport): void;\n /** How many errors are currently held awaiting a transport. */\n readonly buffered: number;\n}\n\n/** Pull the underlying error out of a structurally-typed DOM-ish event. */\nfunction unwrapEvent(event: unknown, key: 'error' | 'reason'): unknown {\n if (typeof event === 'object' && event !== null && key in event) {\n const value = (event as Record<string, unknown>)[key];\n if (value !== undefined && value !== null) return value;\n }\n // An ErrorEvent with no `.error` still carries a message worth reporting.\n if (typeof event === 'object' && event !== null && 'message' in event) {\n return (event as Record<string, unknown>).message;\n }\n return event;\n}\n\n/**\n * Route uncaught errors and unhandled rejections into a `CrashTransport`.\n *\n * `ErrorBoundary` only sees errors thrown during React's render phase. The\n * majority of a game's crashes are not there — they are in the update loop, in\n * an asset load, in a promise nobody awaited — and before this nothing carried\n * them to a transport.\n *\n * Both platforms are handled through the same call:\n *\n * ```ts\n * const capture = installGlobalErrorCapture(globalThis, { transport });\n * // ...\n * capture.uninstall();\n * ```\n *\n * The React Native handler is **chained, not replaced**: whatever handler was\n * installed before still runs, because on RN that handler is what shows the\n * red box in dev and terminates the app on a fatal. Swallowing it would convert\n * a visible crash into a silent one.\n */\nexport function installGlobalErrorCapture(\n target: GlobalErrorTarget,\n options?: GlobalCaptureOptions,\n): GlobalCaptureHandle {\n const bufferSize = Math.max(0, options?.bufferSize ?? 20);\n const context = options?.context ?? {};\n let transport: CrashTransport | null = options?.transport ?? null;\n const pending: ReturnType<typeof createCrashPayload>[] = [];\n let installed = true;\n\n const emit = (error: unknown, extra?: Record<string, unknown>): void => {\n const payload = createCrashPayload(error, extra ? { ...context, ...extra } : { ...context });\n if (transport === null) {\n if (bufferSize === 0) return;\n if (pending.length === bufferSize) pending.shift();\n pending.push(payload);\n return;\n }\n try {\n void transport.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] transport threw while reporting', err);\n }\n };\n\n const onError = (event: unknown): void => {\n emit(unwrapEvent(event, 'error'), { source: 'error' });\n };\n const onRejection = (event: unknown): void => {\n emit(unwrapEvent(event, 'reason'), { source: 'unhandledrejection' });\n };\n\n const canListen =\n typeof target.addEventListener === 'function' &&\n typeof target.removeEventListener === 'function';\n if (canListen) {\n target.addEventListener?.('error', onError);\n target.addEventListener?.('unhandledrejection', onRejection);\n }\n\n const errorUtils = target.ErrorUtils;\n const previousHandler = errorUtils?.getGlobalHandler?.();\n if (errorUtils !== undefined) {\n errorUtils.setGlobalHandler((error: unknown, isFatal?: boolean) => {\n emit(error, { source: 'errorUtils', isFatal: isFatal ?? false });\n // Chain, so the platform's own reporting still happens.\n previousHandler?.(error, isFatal);\n });\n }\n\n return {\n uninstall(): void {\n if (!installed) return;\n installed = false;\n if (canListen) {\n target.removeEventListener?.('error', onError);\n target.removeEventListener?.('unhandledrejection', onRejection);\n }\n if (errorUtils !== undefined && previousHandler !== undefined) {\n errorUtils.setGlobalHandler(previousHandler);\n }\n },\n setTransport(next: CrashTransport): void {\n transport = next;\n while (pending.length > 0) {\n const payload = pending.shift()!;\n try {\n void next.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] transport threw while draining', err);\n }\n }\n },\n get buffered(): number {\n return pending.length;\n },\n };\n}\n\n/**\n * A Sentry-browser-shaped client, described structurally so this package takes\n * no dependency on `@sentry/browser` (or on any particular client).\n */\nexport interface ErrorClientLike {\n captureException(error: unknown, hint?: unknown): unknown;\n}\n\n/**\n * Transport over an injected browser error client.\n *\n * `createSentryTransport` is native-only — it dynamically imports\n * `@sentry/react-native`, which does not resolve on web. This is the web half:\n * the caller supplies an already-initialised client, so this package neither\n * imports nor initialises one.\n *\n * ```ts\n * import * as Sentry from '@sentry/browser';\n * Sentry.init({ dsn });\n * const transport = createClientTransport(Sentry);\n * ```\n *\n * The payload is rebuilt into an `Error` because that is what such clients\n * group by; the original stack is preserved rather than replaced with this\n * function's own.\n */\nexport function createClientTransport(client: ErrorClientLike): CrashTransport {\n return {\n report(payload): void {\n const error = new Error(payload.message);\n error.name = payload.name;\n if (payload.stack !== null) error.stack = payload.stack;\n try {\n client.captureException(error, { extra: payload.context });\n } catch (err) {\n console.error('[@flare-engine/errors] client.captureException threw', err);\n }\n },\n };\n}\n","import type { CrashPayload } from './crash-payload.js';\n\n/**\n * Pluggable transport for reporting crashes. Implementations send the payload\n * wherever they need — Sentry, Crashlytics, an HTTP endpoint, or nowhere.\n */\nexport interface CrashTransport {\n report(payload: CrashPayload): void | Promise<void>;\n}\n\n/** Transport that discards every payload. The default. */\nexport function createNoopTransport(): CrashTransport {\n return {\n report() {\n /* no-op */\n },\n };\n}\n\n/**\n * Transport that logs payloads via `console.error`. Useful in development and\n * as a wrapper around another transport when debugging.\n */\nexport function createConsoleTransport(): CrashTransport {\n return {\n report(payload) {\n console.error('[@flare-engine/errors]', payload);\n },\n };\n}\n","import type { Integration } from '@sentry/react-native';\nimport type { CrashPayload } from '../crash-payload.js';\nimport type { CrashTransport } from '../transport.js';\nimport { createNoopTransport } from '../transport.js';\n\nexport interface SentryTransportOptions {\n dsn?: string;\n environment?: string;\n release?: string;\n sampleRate?: number;\n enabled?: boolean;\n}\n\n// Sentry must send only what `report()` hands it (ADR-0008). The SDK's default\n// integrations include its own global error/rejection handlers, which report\n// outside the transport and so outside any consent check placed in front of\n// it, plus collectors (breadcrumbs, device context) that attach data to every\n// event. Only event processors that enrich an event already in flight are kept.\n// Fail-safe: a name that does not match on some SDK major only loses that\n// enrichment; an unknown name can never add a capture path.\nconst KEPT_INTEGRATIONS: ReadonlySet<string> = new Set([\n 'RewriteFrames',\n 'Release',\n 'DebugMeta',\n 'SdkInfo',\n 'Dedupe',\n 'InboundFilters',\n 'NativeLinkedErrors',\n 'EventOrigin',\n]);\n\nfunction keepEventProcessors(defaults: Integration[]): Integration[] {\n return defaults.filter((integration) => KEPT_INTEGRATIONS.has(integration.name));\n}\n\nexport function createSentryTransport(opts: SentryTransportOptions): CrashTransport {\n if (!opts.dsn || opts.enabled === false) {\n return createNoopTransport();\n }\n\n const dsn = opts.dsn;\n type SentryMod = typeof import('@sentry/react-native');\n let mod: SentryMod | null = null;\n let loadFailed = false;\n\n return {\n async report(payload: CrashPayload): Promise<void> {\n if (loadFailed) return;\n\n if (mod === null) {\n try {\n mod = await import('@sentry/react-native');\n mod.init({\n dsn,\n environment: opts.environment,\n release: opts.release,\n sampleRate: opts.sampleRate,\n integrations: keepEventProcessors,\n enableAutoSessionTracking: false,\n enableNativeCrashHandling: false,\n enableAppHangTracking: false,\n enableWatchdogTerminationTracking: false,\n sendClientReports: false,\n });\n } catch {\n console.error(\n '[@flare-engine/errors] Failed to load @sentry/react-native — degrading to noop',\n );\n loadFailed = true;\n return;\n }\n }\n\n try {\n const err = Object.assign(new Error(payload.message), { name: payload.name });\n if (payload.stack !== null) err.stack = payload.stack;\n mod.captureException(err, {\n extra: { ...payload.context, capturedAt: payload.timestamp },\n });\n } catch {\n console.error('[@flare-engine/errors] Sentry captureException failed');\n }\n },\n };\n}\n"],"mappings":";;;AAEA,SAAgB,kBAAkB,GAAG,YAA8C;CACjF,OAAO,EACL,MAAM,OAAO,SAAS;EACpB,KAAK,MAAM,KAAK,YACd,IAAI;GACF,MAAM,EAAE,OAAO,OAAO;EACxB,SAAS,KAAK;GACZ,QAAQ,MAAM,mEAAmE,GAAG;EACtF;CAEJ,EACF;AACF;;;;;;;ACOA,SAAgB,mBACd,OACA,UAAmC,CAAC,GACtB;CACd,IAAI,iBAAiB,OACnB,OAAO;EACL,SAAS,MAAM;EACf,MAAM,MAAM;EACZ,OAAO,MAAM,SAAS;EACtB,WAAW,KAAK,IAAI;EACpB;CACF;CAEF,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE,SAAS;EAAO,MAAM;EA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;GACnB,IAAI,KAAK;IACP;IACA,aAAa,KAAK;IAClB,SAAS,KAAK;IACd,YAAY,KAAK;IACjB,cAAc;IACd,2BAA2B;IAC3B,2BAA2B;IAC3B,uBAAuB;IACvB,mCAAmC;IACnC,mBAAmB;GACrB,CAAC;EACH,QAAQ;GACN,QAAQ,MACN,gFACF;GACA,aAAa;GACb;EACF;EAGF,IAAI;GACF,MAAM,MAAM,OAAO,OAAO,IAAI,MAAM,QAAQ,OAAO,GAAG,EAAE,MAAM,QAAQ,KAAK,CAAC;GAC5E,IAAI,QAAQ,UAAU,MAAM,IAAI,QAAQ,QAAQ;GAChD,IAAI,iBAAiB,KAAK,EACxB,OAAO;IAAE,GAAG,QAAQ;IAAS,YAAY,QAAQ;GAAU,EAC7D,CAAC;EACH,QAAQ;GACN,QAAQ,MAAM,uDAAuD;EACvE;CACF,EACF;AACF"}
package/dist/index.mjs CHANGED
@@ -74,6 +74,137 @@ var ErrorBoundary = class extends Component {
74
74
  }
75
75
  };
76
76
  //#endregion
77
+ //#region src/global-capture.ts
78
+ /** Pull the underlying error out of a structurally-typed DOM-ish event. */
79
+ function unwrapEvent(event, key) {
80
+ if (typeof event === "object" && event !== null && key in event) {
81
+ const value = event[key];
82
+ if (value !== void 0 && value !== null) return value;
83
+ }
84
+ if (typeof event === "object" && event !== null && "message" in event) return event.message;
85
+ return event;
86
+ }
87
+ /**
88
+ * Route uncaught errors and unhandled rejections into a `CrashTransport`.
89
+ *
90
+ * `ErrorBoundary` only sees errors thrown during React's render phase. The
91
+ * majority of a game's crashes are not there — they are in the update loop, in
92
+ * an asset load, in a promise nobody awaited — and before this nothing carried
93
+ * them to a transport.
94
+ *
95
+ * Both platforms are handled through the same call:
96
+ *
97
+ * ```ts
98
+ * const capture = installGlobalErrorCapture(globalThis, { transport });
99
+ * // ...
100
+ * capture.uninstall();
101
+ * ```
102
+ *
103
+ * The React Native handler is **chained, not replaced**: whatever handler was
104
+ * installed before still runs, because on RN that handler is what shows the
105
+ * red box in dev and terminates the app on a fatal. Swallowing it would convert
106
+ * a visible crash into a silent one.
107
+ */
108
+ function installGlobalErrorCapture(target, options) {
109
+ const bufferSize = Math.max(0, options?.bufferSize ?? 20);
110
+ const context = options?.context ?? {};
111
+ let transport = options?.transport ?? null;
112
+ const pending = [];
113
+ let installed = true;
114
+ const emit = (error, extra) => {
115
+ const payload = createCrashPayload(error, extra ? {
116
+ ...context,
117
+ ...extra
118
+ } : { ...context });
119
+ if (transport === null) {
120
+ if (bufferSize === 0) return;
121
+ if (pending.length === bufferSize) pending.shift();
122
+ pending.push(payload);
123
+ return;
124
+ }
125
+ try {
126
+ transport.report(payload);
127
+ } catch (err) {
128
+ console.error("[@flare-engine/errors] transport threw while reporting", err);
129
+ }
130
+ };
131
+ const onError = (event) => {
132
+ emit(unwrapEvent(event, "error"), { source: "error" });
133
+ };
134
+ const onRejection = (event) => {
135
+ emit(unwrapEvent(event, "reason"), { source: "unhandledrejection" });
136
+ };
137
+ const canListen = typeof target.addEventListener === "function" && typeof target.removeEventListener === "function";
138
+ if (canListen) {
139
+ target.addEventListener?.("error", onError);
140
+ target.addEventListener?.("unhandledrejection", onRejection);
141
+ }
142
+ const errorUtils = target.ErrorUtils;
143
+ const previousHandler = errorUtils?.getGlobalHandler?.();
144
+ if (errorUtils !== void 0) errorUtils.setGlobalHandler((error, isFatal) => {
145
+ emit(error, {
146
+ source: "errorUtils",
147
+ isFatal: isFatal ?? false
148
+ });
149
+ previousHandler?.(error, isFatal);
150
+ });
151
+ return {
152
+ uninstall() {
153
+ if (!installed) return;
154
+ installed = false;
155
+ if (canListen) {
156
+ target.removeEventListener?.("error", onError);
157
+ target.removeEventListener?.("unhandledrejection", onRejection);
158
+ }
159
+ if (errorUtils !== void 0 && previousHandler !== void 0) errorUtils.setGlobalHandler(previousHandler);
160
+ },
161
+ setTransport(next) {
162
+ transport = next;
163
+ while (pending.length > 0) {
164
+ const payload = pending.shift();
165
+ try {
166
+ next.report(payload);
167
+ } catch (err) {
168
+ console.error("[@flare-engine/errors] transport threw while draining", err);
169
+ }
170
+ }
171
+ },
172
+ get buffered() {
173
+ return pending.length;
174
+ }
175
+ };
176
+ }
177
+ /**
178
+ * Transport over an injected browser error client.
179
+ *
180
+ * `createSentryTransport` is native-only — it dynamically imports
181
+ * `@sentry/react-native`, which does not resolve on web. This is the web half:
182
+ * the caller supplies an already-initialised client, so this package neither
183
+ * imports nor initialises one.
184
+ *
185
+ * ```ts
186
+ * import * as Sentry from '@sentry/browser';
187
+ * Sentry.init({ dsn });
188
+ * const transport = createClientTransport(Sentry);
189
+ * ```
190
+ *
191
+ * The payload is rebuilt into an `Error` because that is what such clients
192
+ * group by; the original stack is preserved rather than replaced with this
193
+ * function's own.
194
+ */
195
+ function createClientTransport(client) {
196
+ return { report(payload) {
197
+ const error = new Error(payload.message);
198
+ error.name = payload.name;
199
+ if (payload.stack !== null) error.stack = payload.stack;
200
+ try {
201
+ client.captureException(error, { extra: payload.context });
202
+ } catch (err) {
203
+ console.error("[@flare-engine/errors] client.captureException threw", err);
204
+ }
205
+ } };
206
+ }
207
+ //#endregion
77
208
  //#region src/transport.ts
78
209
  /** Transport that discards every payload. The default. */
79
210
  function createNoopTransport() {
@@ -90,6 +221,19 @@ function createConsoleTransport() {
90
221
  }
91
222
  //#endregion
92
223
  //#region src/transports/sentry.ts
224
+ const KEPT_INTEGRATIONS = /* @__PURE__ */ new Set([
225
+ "RewriteFrames",
226
+ "Release",
227
+ "DebugMeta",
228
+ "SdkInfo",
229
+ "Dedupe",
230
+ "InboundFilters",
231
+ "NativeLinkedErrors",
232
+ "EventOrigin"
233
+ ]);
234
+ function keepEventProcessors(defaults) {
235
+ return defaults.filter((integration) => KEPT_INTEGRATIONS.has(integration.name));
236
+ }
93
237
  function createSentryTransport(opts) {
94
238
  if (!opts.dsn || opts.enabled === false) return createNoopTransport();
95
239
  const dsn = opts.dsn;
@@ -103,7 +247,13 @@ function createSentryTransport(opts) {
103
247
  dsn,
104
248
  environment: opts.environment,
105
249
  release: opts.release,
106
- sampleRate: opts.sampleRate
250
+ sampleRate: opts.sampleRate,
251
+ integrations: keepEventProcessors,
252
+ enableAutoSessionTracking: false,
253
+ enableNativeCrashHandling: false,
254
+ enableAppHangTracking: false,
255
+ enableWatchdogTerminationTracking: false,
256
+ sendClientReports: false
107
257
  });
108
258
  } catch {
109
259
  console.error("[@flare-engine/errors] Failed to load @sentry/react-native — degrading to noop");
@@ -123,6 +273,6 @@ function createSentryTransport(opts) {
123
273
  } };
124
274
  }
125
275
  //#endregion
126
- export { ErrorBoundary, composeTransports, createConsoleTransport, createCrashPayload, createNoopTransport, createSentryTransport };
276
+ export { ErrorBoundary, composeTransports, createClientTransport, createConsoleTransport, createCrashPayload, createNoopTransport, createSentryTransport, installGlobalErrorCapture };
127
277
 
128
278
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/compose.ts","../src/crash-payload.ts","../src/error-boundary.tsx","../src/transport.ts","../src/transports/sentry.ts"],"sourcesContent":["import type { CrashTransport } from './transport.js';\n\nexport function composeTransports(...transports: CrashTransport[]): CrashTransport {\n return {\n async report(payload) {\n for (const t of transports) {\n try {\n await t.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] composeTransports: child transport threw', err);\n }\n }\n },\n };\n}\n","/**\n * Serializable crash payload. Everything here is JSON-safe so transports can\n * post it to Sentry / Crashlytics / a custom HTTP endpoint without extra work.\n */\nexport interface CrashPayload {\n /** Error message. */\n message: string;\n /** Error name (e.g., `TypeError`). */\n name: string;\n /** Captured stack trace, if available. */\n stack: string | null;\n /** Monotonic ms timestamp — `Date.now()` at capture. */\n timestamp: number;\n /** Optional free-form context supplied by the caller. */\n context: Record<string, unknown>;\n}\n\n/**\n * Capture an unknown thrown value as a serializable crash payload. Handles\n * `Error` instances, string throws, and arbitrary values.\n */\nexport function createCrashPayload(\n error: unknown,\n context: Record<string, unknown> = {},\n): CrashPayload {\n if (error instanceof Error) {\n return {\n message: error.message,\n name: error.name,\n stack: error.stack ?? null,\n timestamp: Date.now(),\n context,\n };\n }\n if (typeof error === 'string') {\n return { message: error, name: 'Error', stack: null, timestamp: Date.now(), context };\n }\n let message: string;\n try {\n message = JSON.stringify(error);\n } catch {\n message = String(error);\n }\n return { message, name: 'NonError', stack: null, timestamp: Date.now(), context };\n}\n","import { Component, type ErrorInfo, type ReactNode } from 'react';\nimport { type CrashPayload, createCrashPayload } from './crash-payload.js';\nimport type { CrashTransport } from './transport.js';\n\nexport interface ErrorBoundaryProps {\n children: ReactNode;\n /** Rendered when an error is caught. Receives the payload + a reset callback. */\n fallback: (payload: CrashPayload, reset: () => void) => ReactNode;\n /** Transport invoked once per caught error. */\n transport?: CrashTransport;\n /** Additional context merged into every payload captured by this boundary. */\n context?: Record<string, unknown>;\n /** Called with both the raw error and the payload for custom side effects. */\n onError?: (error: unknown, payload: CrashPayload) => void;\n}\n\ninterface ErrorBoundaryState {\n payload: CrashPayload | null;\n}\n\n/**\n * React error boundary that captures render-phase errors into a structured\n * `CrashPayload`, forwards it to an optional transport, and renders the\n * caller-supplied fallback.\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n state: ErrorBoundaryState = { payload: null };\n\n static getDerivedStateFromError(error: unknown): ErrorBoundaryState {\n return { payload: createCrashPayload(error) };\n }\n\n componentDidCatch(error: unknown, info: ErrorInfo): void {\n const context = {\n ...this.props.context,\n componentStack: info.componentStack ?? null,\n };\n const payload = createCrashPayload(error, context);\n this.setState({ payload });\n this.props.transport?.report(payload);\n this.props.onError?.(error, payload);\n }\n\n reset = (): void => {\n this.setState({ payload: null });\n };\n\n render(): ReactNode {\n if (this.state.payload !== null) {\n return this.props.fallback(this.state.payload, this.reset);\n }\n return this.props.children;\n }\n}\n","import type { CrashPayload } from './crash-payload.js';\n\n/**\n * Pluggable transport for reporting crashes. Implementations send the payload\n * wherever they need — Sentry, Crashlytics, an HTTP endpoint, or nowhere.\n */\nexport interface CrashTransport {\n report(payload: CrashPayload): void | Promise<void>;\n}\n\n/** Transport that discards every payload. The default. */\nexport function createNoopTransport(): CrashTransport {\n return {\n report() {\n /* no-op */\n },\n };\n}\n\n/**\n * Transport that logs payloads via `console.error`. Useful in development and\n * as a wrapper around another transport when debugging.\n */\nexport function createConsoleTransport(): CrashTransport {\n return {\n report(payload) {\n console.error('[@flare-engine/errors]', payload);\n },\n };\n}\n","import type { CrashPayload } from '../crash-payload.js';\nimport type { CrashTransport } from '../transport.js';\nimport { createNoopTransport } from '../transport.js';\n\nexport interface SentryTransportOptions {\n dsn?: string;\n environment?: string;\n release?: string;\n sampleRate?: number;\n enabled?: boolean;\n}\n\nexport function createSentryTransport(opts: SentryTransportOptions): CrashTransport {\n if (!opts.dsn || opts.enabled === false) {\n return createNoopTransport();\n }\n\n const dsn = opts.dsn;\n type SentryMod = typeof import('@sentry/react-native');\n let mod: SentryMod | null = null;\n let loadFailed = false;\n\n return {\n async report(payload: CrashPayload): Promise<void> {\n if (loadFailed) return;\n\n if (mod === null) {\n try {\n mod = await import('@sentry/react-native');\n mod.init({\n dsn,\n environment: opts.environment,\n release: opts.release,\n sampleRate: opts.sampleRate,\n });\n } catch {\n console.error(\n '[@flare-engine/errors] Failed to load @sentry/react-native — degrading to noop',\n );\n loadFailed = true;\n return;\n }\n }\n\n try {\n const err = Object.assign(new Error(payload.message), { name: payload.name });\n if (payload.stack !== null) err.stack = payload.stack;\n mod.captureException(err, {\n extra: { ...payload.context, capturedAt: payload.timestamp },\n });\n } catch {\n console.error('[@flare-engine/errors] Sentry captureException failed');\n }\n },\n };\n}\n"],"mappings":";;AAEA,SAAgB,kBAAkB,GAAG,YAA8C;CACjF,OAAO,EACL,MAAM,OAAO,SAAS;EACpB,KAAK,MAAM,KAAK,YACd,IAAI;GACF,MAAM,EAAE,OAAO,OAAO;EACxB,SAAS,KAAK;GACZ,QAAQ,MAAM,mEAAmE,GAAG;EACtF;CAEJ,EACF;AACF;;;;;;;ACOA,SAA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BAAsB,MAA8C;CAClF,IAAI,CAAC,KAAK,OAAO,KAAK,YAAY,OAChC,OAAO,oBAAoB;CAG7B,MAAM,MAAM,KAAK;CAEjB,IAAI,MAAwB;CAC5B,IAAI,aAAa;CAEjB,OAAO,EACL,MAAM,OAAO,SAAsC;EACjD,IAAI,YAAY;EAEhB,IAAI,QAAQ,MACV,IAAI;GACF,MAAM,MAAM,OAAO;GACnB,IAAI,KAAK;IACP;IACA,aAAa,KAAK;IAClB,SAAS,KAAK;IACd,YAAY,KAAK;GACnB,CAAC;EACH,QAAQ;GACN,QAAQ,MACN,gFACF;GACA,aAAa;GACb;EACF;EAGF,IAAI;GACF,MAAM,MAAM,OAAO,OAAO,IAAI,MAAM,QAAQ,OAAO,GAAG,EAAE,MAAM,QAAQ,KAAK,CAAC;GAC5E,IAAI,QAAQ,UAAU,MAAM,IAAI,QAAQ,QAAQ;GAChD,IAAI,iBAAiB,KAAK,EACxB,OAAO;IAAE,GAAG,QAAQ;IAAS,YAAY,QAAQ;GAAU,EAC7D,CAAC;EACH,QAAQ;GACN,QAAQ,MAAM,uDAAuD;EACvE;CACF,EACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/compose.ts","../src/crash-payload.ts","../src/error-boundary.tsx","../src/global-capture.ts","../src/transport.ts","../src/transports/sentry.ts"],"sourcesContent":["import type { CrashTransport } from './transport.js';\n\nexport function composeTransports(...transports: CrashTransport[]): CrashTransport {\n return {\n async report(payload) {\n for (const t of transports) {\n try {\n await t.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] composeTransports: child transport threw', err);\n }\n }\n },\n };\n}\n","/**\n * Serializable crash payload. Everything here is JSON-safe so transports can\n * post it to Sentry / Crashlytics / a custom HTTP endpoint without extra work.\n */\nexport interface CrashPayload {\n /** Error message. */\n message: string;\n /** Error name (e.g., `TypeError`). */\n name: string;\n /** Captured stack trace, if available. */\n stack: string | null;\n /** Monotonic ms timestamp — `Date.now()` at capture. */\n timestamp: number;\n /** Optional free-form context supplied by the caller. */\n context: Record<string, unknown>;\n}\n\n/**\n * Capture an unknown thrown value as a serializable crash payload. Handles\n * `Error` instances, string throws, and arbitrary values.\n */\nexport function createCrashPayload(\n error: unknown,\n context: Record<string, unknown> = {},\n): CrashPayload {\n if (error instanceof Error) {\n return {\n message: error.message,\n name: error.name,\n stack: error.stack ?? null,\n timestamp: Date.now(),\n context,\n };\n }\n if (typeof error === 'string') {\n return { message: error, name: 'Error', stack: null, timestamp: Date.now(), context };\n }\n let message: string;\n try {\n message = JSON.stringify(error);\n } catch {\n message = String(error);\n }\n return { message, name: 'NonError', stack: null, timestamp: Date.now(), context };\n}\n","import { Component, type ErrorInfo, type ReactNode } from 'react';\nimport { type CrashPayload, createCrashPayload } from './crash-payload.js';\nimport type { CrashTransport } from './transport.js';\n\nexport interface ErrorBoundaryProps {\n children: ReactNode;\n /** Rendered when an error is caught. Receives the payload + a reset callback. */\n fallback: (payload: CrashPayload, reset: () => void) => ReactNode;\n /** Transport invoked once per caught error. */\n transport?: CrashTransport;\n /** Additional context merged into every payload captured by this boundary. */\n context?: Record<string, unknown>;\n /** Called with both the raw error and the payload for custom side effects. */\n onError?: (error: unknown, payload: CrashPayload) => void;\n}\n\ninterface ErrorBoundaryState {\n payload: CrashPayload | null;\n}\n\n/**\n * React error boundary that captures render-phase errors into a structured\n * `CrashPayload`, forwards it to an optional transport, and renders the\n * caller-supplied fallback.\n */\nexport class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {\n state: ErrorBoundaryState = { payload: null };\n\n static getDerivedStateFromError(error: unknown): ErrorBoundaryState {\n return { payload: createCrashPayload(error) };\n }\n\n componentDidCatch(error: unknown, info: ErrorInfo): void {\n const context = {\n ...this.props.context,\n componentStack: info.componentStack ?? null,\n };\n const payload = createCrashPayload(error, context);\n this.setState({ payload });\n this.props.transport?.report(payload);\n this.props.onError?.(error, payload);\n }\n\n reset = (): void => {\n this.setState({ payload: null });\n };\n\n render(): ReactNode {\n if (this.state.payload !== null) {\n return this.props.fallback(this.state.payload, this.reset);\n }\n return this.props.children;\n }\n}\n","import { createCrashPayload } from './crash-payload.js';\nimport type { CrashTransport } from './transport.js';\n\n/**\n * React Native's `global.ErrorUtils`, described structurally so this package\n * needs no React Native dependency or types.\n */\nexport interface ErrorUtilsLike {\n getGlobalHandler?(): ((error: unknown, isFatal?: boolean) => void) | undefined;\n setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;\n}\n\n/**\n * What `installGlobalErrorCapture` needs from a global object.\n *\n * Both members are optional and independent, so one call handles either\n * platform: on web `globalThis` supplies `addEventListener`, on React Native it\n * supplies `ErrorUtils`, and in a test you pass a hand-built fake. Nothing here\n * references `window`, `document` or any RN type.\n */\nexport interface GlobalErrorTarget {\n addEventListener?(type: string, listener: (event: unknown) => void): void;\n removeEventListener?(type: string, listener: (event: unknown) => void): void;\n ErrorUtils?: ErrorUtilsLike;\n}\n\n/** Options for `installGlobalErrorCapture`. */\nexport interface GlobalCaptureOptions {\n /**\n * Where captured errors go. May be omitted at install and attached later with\n * `setTransport` — errors raised in between are held in the buffer below\n * rather than dropped.\n */\n transport?: CrashTransport;\n /**\n * How many pre-transport errors to retain. Default 20. The oldest is dropped\n * once full: a boot loop should not grow memory without bound, and the first\n * errors are the ones worth keeping.\n */\n bufferSize?: number;\n /** Context merged into every payload this capture produces. */\n context?: Record<string, unknown>;\n}\n\n/** Handle returned by `installGlobalErrorCapture`. */\nexport interface GlobalCaptureHandle {\n /**\n * Detach every handler this call installed and restore whatever was there\n * before. Safe to call more than once.\n */\n uninstall(): void;\n /** Attach or replace the transport, draining any buffered errors into it. */\n setTransport(transport: CrashTransport): void;\n /** How many errors are currently held awaiting a transport. */\n readonly buffered: number;\n}\n\n/** Pull the underlying error out of a structurally-typed DOM-ish event. */\nfunction unwrapEvent(event: unknown, key: 'error' | 'reason'): unknown {\n if (typeof event === 'object' && event !== null && key in event) {\n const value = (event as Record<string, unknown>)[key];\n if (value !== undefined && value !== null) return value;\n }\n // An ErrorEvent with no `.error` still carries a message worth reporting.\n if (typeof event === 'object' && event !== null && 'message' in event) {\n return (event as Record<string, unknown>).message;\n }\n return event;\n}\n\n/**\n * Route uncaught errors and unhandled rejections into a `CrashTransport`.\n *\n * `ErrorBoundary` only sees errors thrown during React's render phase. The\n * majority of a game's crashes are not there — they are in the update loop, in\n * an asset load, in a promise nobody awaited — and before this nothing carried\n * them to a transport.\n *\n * Both platforms are handled through the same call:\n *\n * ```ts\n * const capture = installGlobalErrorCapture(globalThis, { transport });\n * // ...\n * capture.uninstall();\n * ```\n *\n * The React Native handler is **chained, not replaced**: whatever handler was\n * installed before still runs, because on RN that handler is what shows the\n * red box in dev and terminates the app on a fatal. Swallowing it would convert\n * a visible crash into a silent one.\n */\nexport function installGlobalErrorCapture(\n target: GlobalErrorTarget,\n options?: GlobalCaptureOptions,\n): GlobalCaptureHandle {\n const bufferSize = Math.max(0, options?.bufferSize ?? 20);\n const context = options?.context ?? {};\n let transport: CrashTransport | null = options?.transport ?? null;\n const pending: ReturnType<typeof createCrashPayload>[] = [];\n let installed = true;\n\n const emit = (error: unknown, extra?: Record<string, unknown>): void => {\n const payload = createCrashPayload(error, extra ? { ...context, ...extra } : { ...context });\n if (transport === null) {\n if (bufferSize === 0) return;\n if (pending.length === bufferSize) pending.shift();\n pending.push(payload);\n return;\n }\n try {\n void transport.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] transport threw while reporting', err);\n }\n };\n\n const onError = (event: unknown): void => {\n emit(unwrapEvent(event, 'error'), { source: 'error' });\n };\n const onRejection = (event: unknown): void => {\n emit(unwrapEvent(event, 'reason'), { source: 'unhandledrejection' });\n };\n\n const canListen =\n typeof target.addEventListener === 'function' &&\n typeof target.removeEventListener === 'function';\n if (canListen) {\n target.addEventListener?.('error', onError);\n target.addEventListener?.('unhandledrejection', onRejection);\n }\n\n const errorUtils = target.ErrorUtils;\n const previousHandler = errorUtils?.getGlobalHandler?.();\n if (errorUtils !== undefined) {\n errorUtils.setGlobalHandler((error: unknown, isFatal?: boolean) => {\n emit(error, { source: 'errorUtils', isFatal: isFatal ?? false });\n // Chain, so the platform's own reporting still happens.\n previousHandler?.(error, isFatal);\n });\n }\n\n return {\n uninstall(): void {\n if (!installed) return;\n installed = false;\n if (canListen) {\n target.removeEventListener?.('error', onError);\n target.removeEventListener?.('unhandledrejection', onRejection);\n }\n if (errorUtils !== undefined && previousHandler !== undefined) {\n errorUtils.setGlobalHandler(previousHandler);\n }\n },\n setTransport(next: CrashTransport): void {\n transport = next;\n while (pending.length > 0) {\n const payload = pending.shift()!;\n try {\n void next.report(payload);\n } catch (err) {\n console.error('[@flare-engine/errors] transport threw while draining', err);\n }\n }\n },\n get buffered(): number {\n return pending.length;\n },\n };\n}\n\n/**\n * A Sentry-browser-shaped client, described structurally so this package takes\n * no dependency on `@sentry/browser` (or on any particular client).\n */\nexport interface ErrorClientLike {\n captureException(error: unknown, hint?: unknown): unknown;\n}\n\n/**\n * Transport over an injected browser error client.\n *\n * `createSentryTransport` is native-only — it dynamically imports\n * `@sentry/react-native`, which does not resolve on web. This is the web half:\n * the caller supplies an already-initialised client, so this package neither\n * imports nor initialises one.\n *\n * ```ts\n * import * as Sentry from '@sentry/browser';\n * Sentry.init({ dsn });\n * const transport = createClientTransport(Sentry);\n * ```\n *\n * The payload is rebuilt into an `Error` because that is what such clients\n * group by; the original stack is preserved rather than replaced with this\n * function's own.\n */\nexport function createClientTransport(client: ErrorClientLike): CrashTransport {\n return {\n report(payload): void {\n const error = new Error(payload.message);\n error.name = payload.name;\n if (payload.stack !== null) error.stack = payload.stack;\n try {\n client.captureException(error, { extra: payload.context });\n } catch (err) {\n console.error('[@flare-engine/errors] client.captureException threw', err);\n }\n },\n };\n}\n","import type { CrashPayload } from './crash-payload.js';\n\n/**\n * Pluggable transport for reporting crashes. Implementations send the payload\n * wherever they need — Sentry, Crashlytics, an HTTP endpoint, or nowhere.\n */\nexport interface CrashTransport {\n report(payload: CrashPayload): void | Promise<void>;\n}\n\n/** Transport that discards every payload. The default. */\nexport function createNoopTransport(): CrashTransport {\n return {\n report() {\n /* no-op */\n },\n };\n}\n\n/**\n * Transport that logs payloads via `console.error`. Useful in development and\n * as a wrapper around another transport when debugging.\n */\nexport function createConsoleTransport(): CrashTransport {\n return {\n report(payload) {\n console.error('[@flare-engine/errors]', payload);\n },\n };\n}\n","import type { Integration } from '@sentry/react-native';\nimport type { CrashPayload } from '../crash-payload.js';\nimport type { CrashTransport } from '../transport.js';\nimport { createNoopTransport } from '../transport.js';\n\nexport interface SentryTransportOptions {\n dsn?: string;\n environment?: string;\n release?: string;\n sampleRate?: number;\n enabled?: boolean;\n}\n\n// Sentry must send only what `report()` hands it (ADR-0008). The SDK's default\n// integrations include its own global error/rejection handlers, which report\n// outside the transport and so outside any consent check placed in front of\n// it, plus collectors (breadcrumbs, device context) that attach data to every\n// event. Only event processors that enrich an event already in flight are kept.\n// Fail-safe: a name that does not match on some SDK major only loses that\n// enrichment; an unknown name can never add a capture path.\nconst KEPT_INTEGRATIONS: ReadonlySet<string> = new Set([\n 'RewriteFrames',\n 'Release',\n 'DebugMeta',\n 'SdkInfo',\n 'Dedupe',\n 'InboundFilters',\n 'NativeLinkedErrors',\n 'EventOrigin',\n]);\n\nfunction keepEventProcessors(defaults: Integration[]): Integration[] {\n return defaults.filter((integration) => KEPT_INTEGRATIONS.has(integration.name));\n}\n\nexport function createSentryTransport(opts: SentryTransportOptions): CrashTransport {\n if (!opts.dsn || opts.enabled === false) {\n return createNoopTransport();\n }\n\n const dsn = opts.dsn;\n type SentryMod = typeof import('@sentry/react-native');\n let mod: SentryMod | null = null;\n let loadFailed = false;\n\n return {\n async report(payload: CrashPayload): Promise<void> {\n if (loadFailed) return;\n\n if (mod === null) {\n try {\n mod = await import('@sentry/react-native');\n mod.init({\n dsn,\n environment: opts.environment,\n release: opts.release,\n sampleRate: opts.sampleRate,\n integrations: keepEventProcessors,\n enableAutoSessionTracking: false,\n enableNativeCrashHandling: false,\n enableAppHangTracking: false,\n enableWatchdogTerminationTracking: false,\n sendClientReports: false,\n });\n } catch {\n console.error(\n '[@flare-engine/errors] Failed to load @sentry/react-native — degrading to noop',\n );\n loadFailed = true;\n return;\n }\n }\n\n try {\n const err = Object.assign(new Error(payload.message), { name: payload.name });\n if (payload.stack !== null) err.stack = payload.stack;\n mod.captureException(err, {\n extra: { ...payload.context, capturedAt: payload.timestamp },\n });\n } catch {\n console.error('[@flare-engine/errors] Sentry captureException failed');\n }\n },\n };\n}\n"],"mappings":";;AAEA,SAAgB,kBAAkB,GAAG,YAA8C;CACjF,OAAO,EACL,MAAM,OAAO,SAAS;EACpB,KAAK,MAAM,KAAK,YACd,IAAI;GACF,MAAM,EAAE,OAAO,OAAO;EACxB,SAAS,KAAK;GACZ,QAAQ,MAAM,mEAAmE,GAAG;EACtF;CAEJ,EACF;AACF;;;;;;;ACOA,SAAgB,mBACd,OACA,UAAmC,CAAC,GACtB;CACd,IAAI,iBAAiB,OACnB,OAAO;EACL,SAAS,MAAM;EACf,MAAM,MAAM;EACZ,OAAO,MAAM,SAAS;EACtB,WAAW,KAAK,IAAI;EACpB;CACF;CAEF,IAAI,OAAO,UAAU,UACnB,OAAO;EAAE,SAAS;EAAO,MAAM;EAAS,OAAO;EAAM,WAAW,KAAK,IAAI;EAAG;CAAQ;CAEtF,IAAI;CACJ,IAAI;EACF,UAAU,KAAK,UAAU,KAAK;CAChC,QAAQ;EACN,UAAU,OAAO,KAAK;CACxB;CACA,OAAO;EAAE;EAAS,MAAM;EAAY,OAAO;EAAM,WAAW,KAAK,IAAI;EAAG;CAAQ;AAClF;;;;;;;;ACnBA,IAAa,gBAAb,cAAmC,UAAkD;CACnF,QAA4B,EAAE,SAAS,KAAK;CAE5C,OAAO,yBAAyB,OAAoC;EAClE,OAAO,EAAE,SAAS,mBAAmB,KAAK,EAAE;CAC9C;CAEA,kBAAkB,OAAgB,MAAuB;EAKvD,MAAM,UAAU,mBAAmB,OAAO;GAHxC,GAAG,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,EAC7D,CAAC;EACH,QAAQ;GACN,QAAQ,MAAM,uDAAuD;EACvE;CACF,EACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/errors",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "React error boundary, structured crash payload, pluggable crash transport",
5
5
  "keywords": ["flare-engine", "errors", "error-boundary", "crash-report", "sentry"],
6
6
  "license": "Apache-2.0",
@@ -32,7 +32,7 @@
32
32
  "files": ["dist", "README.md", "LICENSE", "NOTICE"],
33
33
  "scripts": {
34
34
  "build": "tsdown",
35
- "test": "bun test",
35
+ "test": "bun ../../scripts/test-isolated.mjs",
36
36
  "lint": "biome check src/",
37
37
  "typecheck": "tsc --noEmit"
38
38
  },