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

@sisu-ai/mw-error-boundary

v9.0.1

Published

Catch exceptions from downstream middleware and respond gracefully.

Readme

@sisu-ai/mw-error-boundary

Catch exceptions from downstream middleware and respond gracefully.

Tests CodeQL License Downloads PRs Welcome

Setup

npm i @sisu-ai/mw-error-boundary

Exports

  • errorBoundary(onError: (err, ctx, next) => Promise<void>)
    • Call early in your stack to ensure all downstream errors are caught.
    • Inside onError, you typically:
      • log the error (ctx.log.error(err)),
      • push a friendly assistant message to ctx.messages,
      • optionally write to ctx.stream if you’re mid‑stream.

What It Does

  • Wraps the rest of your pipeline in a try/catch.
  • Invokes your handler with the error and context, so you can log and produce a user‑friendly fallback.
  • Prevents crashes from bubbling to the caller while keeping control in your app.

How It Works

errorBoundary(onError) returns middleware that does:

try {
  await next();
} catch (err) {
  await onError(err, ctx, async () => {}); // next is a no-op in error state
}

Your onError receives (err, ctx, next) where next is a no‑op to signal the boundary is terminal for that request.

Usage

import { Agent } from '@sisu-ai/core';
import { errorBoundary } from '@sisu-ai/mw-error-boundary';

const app = new Agent()
  .use(errorBoundary(async (err, ctx) => {
    ctx.log.error(err);
    // If streaming UI, consider writing to the stream instead/as well.
    ctx.messages.push({ role: 'assistant', content: 'Sorry, something went wrong.' });
  }))
  // ... other middleware

Placement & Ordering

  • Put errorBoundary at or near the top to catch as much as possible.
  • Combine with tracing/usage middleware as needed; if placed before them, those middlewares may not observe the error.
  • If you use a server adapter, ensure it wraps request handling so per‑request errors are isolated.

When To Use

  • Any production app to avoid unhandled rejections crashing the process.
  • CLIs and demos where you want graceful failure and a helpful message.
  • Around tool‑calling loops where third‑party tools may throw.

When Not To Use

  • If you want errors to propagate to an outer boundary (e.g., framework handler) and be handled there.
  • Highly controlled test scenarios where you prefer tests to fail fast instead of being swallowed.

Notes & Gotchas

  • The boundary swallows the error after onError runs; rethrow inside onError if you want upstream handling.
  • Be careful not to leak secrets when logging errors — consider the redacting logger createRedactingLogger from @sisu-ai/core.
  • If you are streaming tokens, write an error notice to ctx.stream and call ctx.stream.end() to close the client stream cleanly.
  • Keep onError fast and robust; avoid throwing inside it.

Community & Support

Discover what you can do through examples or documentation. Check it out at https://github.com/finger-gun/sisu. Example projects live under examples/ in the repo.