npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@flare-engine/errors

v0.4.10

Published

React error boundary, structured crash payload, pluggable crash transport

Readme

@flare-engine/errors

React error boundary + structured crash payloads. createCrashPayload(err, context?) normalizes any thrown value into a stable CrashPayload shape. Pluggable CrashTransport sinks: createNoopTransport, createConsoleTransport, createSentryTransport (lazy-loaded @sentry/react-native, optional peer dep), and composeTransports for fan-out.

Install

bun add @flare-engine/errors

Optional peer deps: react, @sentry/react-native (only if you wire the Sentry transport).

Usage

import { ErrorBoundary, createSentryTransport, createConsoleTransport,
         composeTransports, type CrashPayload } from '@flare-engine/errors';
import type { ReactNode } from 'react';

declare function CrashScreen(props: { err: CrashPayload; onRetry: () => void }): ReactNode;
declare function App(): ReactNode;

const transport = composeTransports(
  createConsoleTransport(),
  createSentryTransport({ dsn: 'https://[email protected]/0', enabled: true }),
);

<ErrorBoundary
  fallback={(err, reset) => <CrashScreen err={err} onRetry={reset} />}
  transport={transport}
  context={{ scene: 'play', level: 4 }}
>
  <App />
</ErrorBoundary>

createSentryTransport starts Sentry with the SDK's own capture switched off — no global error or rejection handlers, no automatic session tracking, no native crash handling, no console/network instrumentation — so Sentry sends only what the transport is given, and a consent check placed in front of the transport holds. Process-wide JS errors reach it through installGlobalErrorCapture (next section). The one exception the transport cannot close: on Android 11+ the native SDK reports past ANRs on its own; if consent must cover those, set the io.sentry.anr.enable meta-data to false in your Android manifest (Sentry Android docs).

Opting a dropped integration back in is a deliberate act: the integrations hook receives the allowlist (kept) and the SDK's own default list (defaults) and returns what init uses. Each entry is a SentryIntegrationLike ({ name }), so no @sentry/react-native type is needed.

import { createSentryTransport } from '@flare-engine/errors';

const transport = createSentryTransport({
  dsn: 'https://[email protected]/0',
  integrations: (kept, defaults) => [
    ...kept,
    ...defaults.filter((integration) => integration.name === 'Breadcrumbs'),
  ],
});

Returning defaults, or passing through any capture integration such as ReactNativeErrorHandlers, re-enables Sentry's own global handlers, which report outside the transport and so outside any consent check placed in front of it. A hook that throws is logged and the allowlist is used.

On consent revocation, close the transport. The Sentry transport awaits the SDK's close() once (only if it was ever loaded), and every later report() sends nothing; a second close() resolves without closing again. composeTransports forwards close() to each child that has one, so the chain from the first example shuts down in one call:

import { composeTransports, createConsoleTransport, createSentryTransport } from '@flare-engine/errors';

const transport = composeTransports(
  createConsoleTransport(),
  createSentryTransport({ dsn: 'https://[email protected]/0' }),
);

// later, when the user withdraws consent:
await transport.close?.();

close is optional on CrashTransport; createNoopTransport, createConsoleTransport and the noop a DSN-less createSentryTransport returns leave it undefined.

Catching what the boundary cannot

ErrorBoundary only sees errors thrown during React's render phase. Most of a game's crashes are not there — they are in the update loop, in an asset load, in a promise nobody awaited. installGlobalErrorCapture routes those into the same transport chain.

import { installGlobalErrorCapture, createConsoleTransport } from '@flare-engine/errors';

// `globalThis` supplies `addEventListener` on web and `ErrorUtils` on React
// Native, so one call covers both.
const capture = installGlobalErrorCapture(globalThis, {
  transport: createConsoleTransport(),
  context: { build: '1.2.3' },
});

// Later, e.g. on scene teardown or hot reload:
capture.uninstall();

The transport can attach after installing. Errors raised in between are held in a small ring buffer (default 20, oldest dropped) and drained on attach, so the crashes that happen during boot — usually the interesting ones — are not lost while your reporter is still initialising:

import { installGlobalErrorCapture, createClientTransport } from '@flare-engine/errors';

declare const Sentry: { captureException(error: unknown, hint?: unknown): unknown };

const capture = installGlobalErrorCapture(globalThis);   // no transport yet
// ... boot, read config, initialise the reporter ...
capture.setTransport(createClientTransport(Sentry));     // buffered errors drain here

Two things worth knowing:

  • On React Native the previous ErrorUtils handler is chained, not replaced — that handler is what shows the red box in development and ends the process on a fatal, so it still runs. uninstall() restores it.
  • createSentryTransport is native-only (it imports @sentry/react-native). createClientTransport is the web counterpart: you initialise a browser client and inject it, so this package depends on no reporter of its own.

See API spec.

License

Apache-2.0