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

ferr

v3.0.6

Published

Expressive error handling with a functional focus

Readme

ferr

ferr is a pragmatic error library for TypeScript/Node. fErr stands for "Fancy Error".

It keeps the native Error model (instanceof Error still works), while making failures easier to compose, enrich, and log in real systems.

The spirit

Most production errors are not one event. They are a chain:

  • low-level failure (cause)
  • service-level context (op, code, context)
  • user-facing intent (clientMsg)
  • breadcrumbs (notes)

ferr is built for that chain.

The goal is not "fancy exceptions." The goal is readable, mergeable, diagnosable errors that survive multiple layers without losing meaning.

Install

pnpm add ferr

Quick start

import { FErr } from 'ferr'

const err = new FErr({
  op: 'loadUser',
  code: 'USER_NOT_FOUND',
  message: 'User lookup failed',
  clientMsg: 'Unable to load account right now',
  context: { userId: 'u_123' },
  cause: new Error('db timeout')
})

console.log(err.toMessageString())
console.log(err.toDetailedString())

Examples

  1. Normalize unknown caught errors
import { FErr } from 'ferr'

try {
  await doWork()
} catch (e) {
  throw FErr.from(e)
    .withOp('service.doWork')
    .withCode('WORK_FAILED')
    .withContext({ jobId: 'j_123' })
}
  1. Add context without mutation
import { FErr } from 'ferr'

const base = new FErr({ op: 'auth.login', message: 'Login failed' })
const enriched = base
  .withContext({ requestId: 'r_123', tenantId: 't_9' })
  .withNotes('retry path used')

// base is unchanged; enriched is a new instance
  1. Merge failures across boundaries
import { FErr } from 'ferr'

const appErr = new FErr({ op: 'createOrder', message: 'Order failed' })
const merged = appErr.mergeAppend(externalErr)
console.log(merged.toDetailedString())
  1. Throw helpers for guard clauses
import { rethrowFerr, throwFerr, throwIfUndefined } from 'ferr'

throwFerr({
  with: {
    op: 'authorize',
    message: 'Unauthorized',
    context: { userId }
  }
})

try {
  await doWork()
} catch (e) {
  rethrowFerr(e, {
    with: { op: 'api.handleRequest', code: 'REQUEST_FAILED', message: 'Request failed' }
  })
}

throwIfUndefined(config, 'boot', 'Missing config')
  1. Wrapper-style throw/rethrow (recommended for service layers)
import { rethrowFerr, throwFerr } from 'ferr'

const authorize = (userId: string) => {
  if (!userId) {
    throwFerr({
      with: {
        op: 'auth.authorize',
        code: 'AUTH_MISSING_USER',
        message: 'Missing user id'
      }
    })
  }
}

const handleRequest = async () => {
  try {
    await authorize('u_123')
  } catch (caught) {
    rethrowFerr(caught, {
      with: {
        op: 'api.handleRequest',
        code: 'REQUEST_FAILED',
        message: 'Request failed'
      }
    })
  }
}

API overview

FErr

  • new FErr(options)
  • FErr.from(input, overrides?)
  • FErr.is(value)
  • mergeAppend(...), mergeUpdate(...)
  • withMessage/withOp/withCode/withClientMsg/withContext/withCause/withNotes
  • toMessageString(), toDetailedString()
  • toOptions(), toJSON()

Throw/rethrow helpers

  • throwFerr, throwFerrIf
  • rethrowFerr
  • throwErr, throwErrIf
  • rethrowAppend, rethrowUpdate
  • throwIfUndefined
  • custom factories: createThrowErr, createThrowErrIf, createThrowIfUndefined

Note: root package exports are intentionally limited to the FErr API and throw/rethrow helpers. Internal utility helpers are implementation details and are not part of the stable public API contract.

Why this over plain Error?

Plain Error is good for simple throw/catch, but it does not define how to:

  • carry structured runtime context
  • merge error information from multiple layers
  • keep short and detailed formats in sync
  • coerce arbitrary thrown values consistently

ferr gives those patterns first-class APIs.

Runtime compatibility

  • Node-first package
  • ESM/CJS build outputs
  • Works with standard try/catch
  • FErr remains instanceof Error

Development

pnpm lint
pnpm sanity
pnpm run viz

Release (Local)

pnpm run release