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

@clov-std/error

v5.0.0

Published

Structured TypeScript exceptions with a machine-readable error key and a typed cause.

Readme

🐞 Clov Error

If you've ever debugged a production incident with nothing but a generic Error("something went wrong"), you know the pain.
This package gives your errors structure, every exception carries a machine-readable code, so you can always branch on what happened instead of grepping a message string.

Why this package?

Vanilla Error objects lack context.
Catching one leaves you matching on error.message strings, which breaks the day someone rewords the message.

@clov-std/error solves that with two classes:

  • Exception - a richer base error carrying a stable code and a typed cause.
  • HttpException - the same, plus a resolved HTTP status.

The code is the point. A low-level library throws Exception with code: 'jwt.token.expired' without knowing anything about transports or locales, and the layer that does know maps that code to a wire format. One direction of dependency, no HTTP concern leaking into a token signer.

No dependencies, no bloat. Just structured errors that make your life easier.

Looking for localized messages? That's @clov-std/i18n.

📌 Table of Contents

✨ Features

  • 🔑 Stable Error Codes : Branch on error.code, never on error.message.
  • 🌐 HTTP When You Need It : HttpException resolves a status from a name ('NOT_FOUND') or a number.
  • 🔗 Typed Cause : cause keeps its shape through the generic, so wrapping an error doesn't lose its type.
  • 🧹 Clean Stack Traces : The constructor frame is stripped, and name reflects the actual subclass.
  • 📦 Zero Dependencies : Pure TypeScript, no runtime globals, tiny footprint.

🔧 Installation

bun add @clov-std/error

⚙️ Usage

Exception - General-Purpose Errors

Use Exception whenever you need a traceable error with more context than a plain Error.

import { Exception } from '@clov-std/error';

throw new Exception('Configuration file not found', {
	code: 'config.file.not-found'
});

The code is what callers should switch on:

try {
	await verifyToken(token);
} catch (err) {
	if (err instanceof Exception && err.code === 'jwt.token.expired') return refresh();
	throw err;
}

You can also wrap a root cause to preserve the original error:

import { Exception } from '@clov-std/error';

try {
	await db.save(user);
} catch (err) {
	throw new Exception('Failed to persist user', { cause: err });
}

What's deliberately not here

No request id, no timestamp. Both belong to the layer that handles the error: a request handler already has an x-request-id (or mints one), and a log sink already stamps every line with a time. Putting them on the error means every throw pays for identity nobody reads.

If an application genuinely needs them on the instance, that's a subclass:

class TracedException extends Exception {
	public readonly uuid: string = crypto.randomUUID();
	public readonly date: Date = new Date();
}

HttpException - Errors Bound to a Status

When a failure has a status, throw HttpException. It takes a status name or a number, and resolves it to error.status:

import { HttpException } from '@clov-std/error';

throw new HttpException('Account not found', {
	code: 'auth.account.not-found',
	status: 'NOT_FOUND' // or 404
});

status is required on purpose: an HTTP exception without one is a bug, and a silent 500 would hide it.

Nothing about RFC 9457 lives here. Your presentation layer maps code to the wire format it needs, which keeps this package usable from a CLI or a worker:

// One adapter, at the boundary
problem({ type: error.code, status: error.status, detail: error.message });

For translated messages, @clov-std/i18n builds on Exception with catalogs of localized templates.

📚 API Reference

Full docs: https://clovlabs.github.io/std/

⚖️ License

MIT - Feel free to use it.

📧 Contact