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

@fab33/fab-errors

v1.0.3

Published

Modern error handling library with typed contexts, Error.cause chains, and ErrorSpecs

Readme

@fab33/fab-errors

npm version License: MIT

Современная, гибкая и типизированная библиотека для обработки ошибок в JavaScript/TypeScript приложениях. Использует нативное свойство Error.cause для цепочек ошибок и декларативные "спецификации ошибок" (ErrorSpec) с типизированным контекстом.

🎯 Ключевые Особенности

  • FabError: Основной класс ошибок, расширяющий Error.
  • 📜 ErrorSpec<TContext>: Декларативное определение "чертежей" ошибок.
  • 🏭 Фабричные функции: Рекомендуемый паттерн для создания FabError.
  • ⛓️ Утилиты для цепочек Error.cause: hasErrorInChain, checkErrorChain.
  • 📦 Модульность и Чистый API.
  • 🔧 Гибкость и Расширяемость.
  • 🔒 TypeScript First: Разработана с упором на статическую типизацию.

Документация: FAB_ERRORS.md

📥 Установка

npm install @fab33/fab-errors
# или
yarn add @fab33/fab-errors
# или
pnpm add @fab33/fab-errors

🚀 Быстрый Старт

import { FabError, type ErrorSpec } from '@fab33/fab-errors';

// 1. Определите контекст и спецификацию для вашей ошибки
interface MyCustomErrorContext {
  itemId: string;
  operation: 'create' | 'update' | 'delete';
}

const MY_CUSTOM_ERROR_SPEC: ErrorSpec<MyCustomErrorContext> = {
  code: 'MY_APP_ITEM_OPERATION_FAILED',
  messageTemplate: 'Operation {operation} for item {itemId} failed.',
  docs: 'https://example.com/docs/errors#item-operation-failed'
};

// 2. (Рекомендуется) Создайте фабричную функцию
function createItemOperationError(
  context: MyCustomErrorContext,
  cause?: Error
): FabError<MyCustomErrorContext> {
  return new FabError(MY_CUSTOM_ERROR_SPEC, context, cause);
}

// 3. Используйте вашу ошибку
function performItemOperation(itemId: string, operation: MyCustomErrorContext['operation']) {
  try {
    // ... какая-то логика, которая может выбросить ошибку ...
    if (Math.random() < 0.5) {
      throw new Error('Low level FS error');
    }
    console.log(`Successfully performed ${operation} for item ${itemId}`);
  } catch (err) {
    // Оборачиваем исходную ошибку
    const cause = err instanceof Error ? err : new Error(String(err));
    throw createItemOperationError({ itemId, operation }, cause);
  }
}

try {
  performItemOperation('item-123', 'update');
} catch (error) {
  if (error instanceof FabError && error.code === MY_CUSTOM_ERROR_SPEC.code) {
    console.error('Caught FabError:');
    console.error('  Code:', error.code);
    console.error('  Message:', error.message);
    console.error('  Context:', error.context); // Типизированный контекст!
    if (error.cause) {
      console.error('  Caused by:', error.cause.message);
    }
  } else {
    console.error('Caught an unknown error:', error);
  }
}

📚 Документация

Полная документация находится в файле docs/FAB_ERRORS.md.

🤝 Участие

Пожалуйста, ознакомьтесь с CONTRIBUTING.md для получения информации о том, как внести свой вклад.

📜 Лицензия

MIT © fab33 (deksden)

Этот рефакторинг должен значительно улучшить DX, надежность и гибкость библиотеки для работы с ошибками. 🥳