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 🙏

© 2024 – Pkg Stats / Ryan Hefner

epicfail

v3.0.0

Published

Better error output for Node.js CLI apps

Downloads

4,051

Readme

Features

npm-version npm-downloads npm bundle size Actions Status: test

epicfail converts unhandledRejection and uncaughtException into graceful and helpful error message for both users and developers.

⬇️ Prints error messages in copy and paste ready Markdown.
🌐 Asks users to report a bug (navigate users to bugs.url in package.json).
🍁 Shows machine environments (OS, Node.js version, etc).
👀 Suggests related issues in GitHub.
🛠 Integration with error aggregation service (like Sentry).

Table of Contents

Install

npm install --save epicfail
# or
yarn add epicfail

Use

ESModules

import { epicfail } from "epicfail";

epicfail(import.meta.url);

// your CLI app code goes here
fs.readFileSync("foo"); // => will cause "ENOENT: no such file or directory, open 'foo'"

CommonJS

const { epicfail } = require("epicfail");

epicfail(require.main.filename);

// your CLI app code goes here
fs.readFileSync("foo"); // => will cause "ENOENT: no such file or directory, open 'foo'"

With stacktrace

Options

stacktrace (default: true)

Show stack trace.

import { epicfail } from "epicfail";

epicfail(import.meta.url, {
  stacktrace: false,
});

Without stacktrace

issues (default: false)

Search and show related issues in GitHub Issues.

import { epicfail } from "epicfail";

epicfail(import.meta.url, {
  issues: true,
});

With issues

env

Show environment information. You can find all possible options here. Set to false to disable it.

import { epicfail } from "epicfail";

epicfail(import.meta.url, {
  env: {
    System: ["OS", "CPU"],
    Binaries: ["Node", "Yarn", "npm"],
    Utilities: ["Git"],
  },
});

Default values:

{
  "System": ["OS"],
  "Binaries": ["Node"]
}

With envinfo

message (default: true)

Show bug tracker URL and ask users to report the error.

import { epicfail } from "epicfail";

epicfail(import.meta.url, { message: false });

assertExpected (default: () => false)

While processing an error, if assertExpected(error) returns true, epicfail just prints the error message without any extra information; which is the same behaviour as the logAndExit() function described below.

import { epicfail } from "epicfail";

epicfail(import.meta.url, {
  assertExpected: (err) => err.name === "ArgumentError",
});

onError (default: undefined)

Pass the function that process the error and returns event id issued by external error aggregation service.

import { epicfail } from "epicfail";
import Sentry from "@sentry/node";

epicfail(import.meta.url, {
  onError: (err) => Sentry.captureException(err), // will returns an event id issued by Sentry
});

Advanced Usage

Print error message without extra information

Use logAndExit() to print error message in red text without any extra information (stack trace, environments, etc), then quit program. It is useful when you just want to show the expected error message without messing STDOUT around with verbose log messages.

import { epicfail, logAndExit } from "epicfail";

epicfail(import.meta.url);

function cli(args) {
  if (args.length === 0) {
    logAndExit("usage: myapp <input>");
  }
}

cli(process.argv.slice(2));

You can also pass an Error instance:

function cli(args) {
  try {
    someFunction();
  } catch (err) {
    logAndExit(err);
  }
}

Sentry integration

import { epicfail } from "epicfail";
import Sentry from "@sentry/node";

epicfail(import.meta.url, {
  stacktrace: false,
  env: false,
  onError: Sentry.captureException, // will returns event_id issued by Sentry
});

Sentry.init({
  dsn: "<your sentry token here>",
  defaultIntegrations: false, // required
});

// your CLI app code goes here
fs.readFileSync("foo"); // => will cause "ENOENT: no such file or directory, open 'foo'"

Sentry integration

Runtime options

import {epicfail} from 'epicfail';

epicfail(import.meta.url);

// 1. Use epicfail property in Error instance.
const expected = new Error('Wooops');
expected.epicfail = { stacktrace: false, env: false, message: false };
throw expected;

// 2. Use fail method
import { fail } from 'epicfail';
fail('Wooops', { stacktrace: false, env: false, message: false });

// 3. Use EpicfailError class (useful in TypeScript)
import { EpicfailError } from 'epicfail';
const err = new EpicfailError('Wooops', { stacktrace: false, env: false, message: false };);
throw err;