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

@erris/core

v1.0.1

Published

Core runtime error contracts for JavaScript and TypeScript.

Readme

@erris/core

Core runtime error contracts, error catalogs, and normalization engine for JavaScript and TypeScript.

npm version License: MIT

@erris/core provides the foundational primitives for building type-safe, namespaced application error systems. It enforces immutable error identity creation, zero-dependency normalization, and strict runtime contracts.


Installation

# npm
npm install @erris/core

# pnpm
pnpm add @erris/core

# yarn
yarn add @erris/core

API Reference & Usage

1. defineErrors(namespace, definitions)

Creates an immutable catalog of namespaced error factories.

import { defineErrors } from "@erris/core"

export const UserErrors = defineErrors("user", {
  NOT_FOUND: {
    message: "Requested user account was not found",
  },
  EMAIL_EXISTS: {
    message: "A user account with this email address already exists",
  },
})

// Factory call creates frozen ErrisError instance
const err = UserErrors.NOT_FOUND({ cause: new Error("DB record null") })

console.log(err.code) // "user.not_found" (type: "user.not_found")
console.log(err.message) // "Requested user account was not found"
console.log(err.cause) // Error("DB record null")

TypeScript Invariants & Autocomplete:

const error = UserErrors.NOT_FOUND()

error.code
//    ^? "user.not_found"

Guarantees:

  • Error codes are automatically lowercased and prefixed (namespace.key_lowercase).
  • Object structures, catalog keys, and generated factory functions are deeply frozen.
  • TypeScript preserves exact string literal types for err.code.

2. combineErrors(...catalogs)

Safely merges multiple domain error catalogs into a single unified catalog while validating code and key uniqueness.

import { defineErrors, combineErrors } from "@erris/core"

const UserErrors = defineErrors("user", {
  NOT_FOUND: { message: "User not found" },
})

const AuthErrors = defineErrors("auth", {
  UNAUTHORIZED: { message: "Unauthorized access" },
})

export const AppErrors = combineErrors(UserErrors, AuthErrors)

// Preserves literal autocomplete types across all combined catalogs
AppErrors.NOT_FOUND()
AppErrors.UNAUTHORIZED()

Guarantees:

  • Prevents duplicate catalog keys or duplicate error code overlaps at runtime.
  • Preserves full TypeScript autocompletion and exact literal type unions.

3. createNormalizer(options)

Constructs a resilient normalization function that maps unknown thrown values into guaranteed ErrisError occurrences.

import { createNormalizer, defineErrors } from "@erris/core"

const SystemErrors = defineErrors("system", {
  INTERNAL: { message: "An unexpected internal server error occurred" },
})

const normalize = createNormalizer({
  fallback: SystemErrors.INTERNAL,
  adapters: [], // Add vendor adapters like @erris/adapter-zod or @erris/adapter-prisma
})

try {
  throw new Error("Something went wrong")
} catch (caught) {
  const err = normalize(caught)
  console.log(err.code) // "system.internal"
  console.log(err.cause) // Error("Something went wrong")
}

Guarantees:

  • Passes existing ErrisError instances through unchanged.
  • Evaluates registered adapters in order until one returns an ErrisError.
  • Never throws exceptions during normalization (catches adapter failures safely).
  • Always returns a valid ErrisError, attaching unhandled values as cause.

4. ErrisError & isErrisError(value)

Base class extending standard JavaScript Error.

import { ErrisError, isErrisError } from "@erris/core"

if (isErrisError(err)) {
  console.log(err.code, err.message)
}
  • code: Read-only, enumerable string literal representing the error identity.
  • cause: Preserves original underlying exceptions without making them enumerable.
  • isErrisError(value): Type guard returning true for valid ErrisError instances.

Full Example

See examples/dogfood-backend for a complete backend example using @erris/core together with HTTP transports and adapters.


Features

  • 🛡️ Zero Runtime Dependencies: Lightweight core built for Node.js, Bun, Deno, and Edge environments.
  • ❄️ Immutable & Frozen: All factories and instances are frozen to prevent tampering.
  • 🔒 Type-Safe Invariants: Full literal type preservation for error codes.

License

MIT © Sreerag Pariyarath