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

@shkumbinhsn/try-catch-eslint

v0.1.3

Published

ESLint plugin to enforce try-catch patterns with @shkumbinhsn/try-catch

Readme

@shkumbinhsn/try-catch-eslint

npm version npm downloads

ESLint plugin to enforce type-safe error handling patterns with @shkumbinhsn/try-catch.

Installation

npm install -D @shkumbinhsn/try-catch-eslint

Peer Dependencies

This plugin requires the following peer dependencies:

  • eslint ^8.0.0 || ^9.0.0
  • @typescript-eslint/parser ^8.0.0
  • typescript >=4.7.0

Setup

ESLint Flat Config (eslint.config.js)

import tryCatchPlugin from "@shkumbinhsn/try-catch-eslint";
import tsParser from "@typescript-eslint/parser";

export default [
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        project: "./tsconfig.json",
      },
    },
    plugins: {
      "@shkumbinhsn/try-catch-eslint": tryCatchPlugin,
    },
    rules: {
      "@shkumbinhsn/try-catch-eslint/require-throws-declaration": "error",
      "@shkumbinhsn/try-catch-eslint/require-try-catch": "warn",
      "@shkumbinhsn/try-catch-eslint/no-unhandled-throws": "error",
    },
  },
];

Using Recommended Config

import tryCatchPlugin from "@shkumbinhsn/try-catch-eslint";
import tsParser from "@typescript-eslint/parser";

export default [
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        project: "./tsconfig.json",
      },
    },
    plugins: {
      "@shkumbinhsn/try-catch-eslint": tryCatchPlugin,
    },
    rules: {
      ...tryCatchPlugin.configs.recommended.rules,
    },
  },
];

Rules

require-throws-declaration

Severity: Error (recommended)

Requires functions with throw statements to declare a Throws<E> return type.

Bad

function riskyOperation(): string {
  if (Math.random() > 0.5) {
    throw new CustomError("Failed"); // Error: Function throws but doesn't declare Throws<E>
  }
  return "success";
}

Good

import { type Throws } from "@shkumbinhsn/try-catch";

function riskyOperation(): string & Throws<CustomError> {
  if (Math.random() > 0.5) {
    throw new CustomError("Failed");
  }
  return "success";
}

Autofix Suggestions

This rule provides suggestions to:

  • Add & Throws<ErrorType> to the return type
  • Wrap return value with tc(value).mightThrow<ErrorType>()
  • Add missing error types to existing Throws<> declaration

require-try-catch

Severity: Warn (recommended)

Warns when calling functions that return Throws<E> without wrapping in tryCatch().

Bad

import { type Throws } from "@shkumbinhsn/try-catch";

function riskyOperation(): string & Throws<CustomError> {
  // ...
}

const result = riskyOperation(); // Warning: Should wrap in tryCatch()

Good

import { tryCatch, type Throws } from "@shkumbinhsn/try-catch";

function riskyOperation(): string & Throws<CustomError> {
  // ...
}

const [data, error] = tryCatch(() => riskyOperation());

Autofix Suggestions

This rule provides a suggestion to wrap the call in tryCatch(() => ...).


no-unhandled-throws

Severity: Error (recommended)

Errors when using the data from tryCatch() without first checking for errors.

Bad

const [data, error] = tryCatch(() => riskyOperation());

console.log(data.value); // Error: Must check error before using data

Good

const [data, error] = tryCatch(() => riskyOperation());

if (error) {
  console.error("Failed:", error.message);
  return;
}

console.log(data.value); // OK: error was checked

Also valid:

const [data, error] = tryCatch(() => riskyOperation());

if (!error) {
  console.log(data.value); // OK: inside !error block
}

Rule Configuration

All rules can be configured with standard ESLint severity levels:

rules: {
  // Turn off
  "@shkumbinhsn/try-catch-eslint/require-throws-declaration": "off",
  
  // Warning
  "@shkumbinhsn/try-catch-eslint/require-try-catch": "warn",
  
  // Error
  "@shkumbinhsn/try-catch-eslint/no-unhandled-throws": "error",
}

How It Works

This plugin uses TypeScript's type information to:

  1. Detect Throws<E> types in function return types
  2. Track throw statements in function bodies
  3. Analyze tryCatch() usage to ensure proper error handling

The plugin requires @typescript-eslint/parser with type information enabled (parserOptions.project).

Related

License

MIT