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

@solvro/error-handling

v1.1.0

Published

Utilities for rich error handling

Readme

Solvro error handling

A small utility library that makes rich error handling easier.

Contents

base

Contains the definition of the BaseError interface and class.

All errors are expected to conform to the IBaseError interface. Non-conformant errors can be corrected/reconstructed using the toIBaseError function. isIBaseError can be used to verify that an error correctly implements IBaseError.

The BaseError interface and class allows errors to contain information about the error code, the suggested response code (if the error is to be sent over HTTP), whether the error should be logged or sent over a network with full details, and more.

See the documentation (in code) for more details.

install-context

This module should be side-effect imported as early as possible.

This module registers the addErrorContext function on all Promises, inspired by Rust's anyhow library.

The following code using addErrorContext...

await someAsyncFunction().addErrorContext("Failed to make some request");

can be written without this library like this:

try {
  await someAsyncFunction();
} catch (e) {
  throw new Error("Failed to make some request", { cause: e });
}

(but that code is much uglier)

addErrorContext can also take in a function as a parameter, in which case it will be called only if the promise rejects. Use this to lazily create context strings with parameters, like this:

for (const item of someArray) {
  await someAsyncFunction(item).addErrorContext(
    () => `Failed to run the function on an item with ID ${item.id}`,
  );
}

The context value can also be an object instead of a simple string, with the same allowed properties as the BaseError constructor options. This allows you to easily set response codes for errors thrown from functions.

await fetchSomeRecordFromTheDatabase().addErrorContext({
  message: "Record not found",
  status: 404,
  code: "E_RECORD_NOT_FOUND",
  silent: true,
});

Reporting

This module contains functions used for analyzing error stacks and reporting them to the console or sending as a JSON response.

The analyzeErrorStack function takes any IBaseError, analyzing it and returning an ErrorReport.

This ErrorReport can then be passed to prepareReportForLogging or serializeErrorReport.

The prepareReportForLogging function converts an ErrorReport to a multi-line string, intended to be logged. The returned string will include the full context stack and stack trace, even if the final ErrorReport had sensitive or silent set.

The serializeErrorReport function strips out unnecessary information (and the causeStack, if sensitive is set), and returns a JSON response, intended to be sent to the client.

These functions can be used to create a full error handler, such as this one for adonis:

export default class HttpExceptionHandler extends ExceptionHandler {
  async handle(error: unknown, ctx: HttpContext) {
    const report = analyzeErrorStack(toIBaseError(error));
    const payload = serializeErrorReport(report, {
      includeStackTrace: !app.inProduction,
    });
    ctx.response.status(report.status).send(payload);
  }

  async report(error: unknown, ctx: HttpContext) {
    const report = analyzeErrorStack(toIBaseError(error));
    if (report.silent) {
      return;
    }
    logger.error(
      `Error thrown while handling route ${ctx.route?.pattern ?? "<unknown>"}: ${prepareReportForLogging(report)}`,
    );
  }
}

License

This library is licensed under MPL-2.0.