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

@dotcom-reliability-kit/crash-handler

v4.1.11

Published

A method to bind an uncaught exception handler to ensure that fatal application errors are logged

Downloads

4,668

Readme

@dotcom-reliability-kit/crash-handler

A method to bind an uncaught exception handler to ensure that fatal application errors are logged. It is a replacement for Sentry fatal error logging. This module is part of FT.com Reliability Kit.

Usage

Install @dotcom-reliability-kit/crash-handler as a dependency:

npm install --save @dotcom-reliability-kit/crash-handler

Include in your code:

import registerCrashHandler from '@dotcom-reliability-kit/crash-handler';
// or
const registerCrashHandler = require('@dotcom-reliability-kit/crash-handler');

registerCrashHandler

The registerCrashHandler function can be used to bind an event handler to the Node.js process.uncaughtException event. This ensures that your application logs a final message before crashing in the event on an unexpected error or promise rejection.

This function should only ever be called once in your app, normally alongside all your setup code (e.g. alongside creating an Express app).

[!TIP] It's not a requirement, but generally the earlier the better with registering an uncaught exception handler – the sooner you register it the more likely you are to catch uncaught exceptions.

registerCrashHandler();

If an error is thrown which will crash your application, error information will be logged and then the process will exit with the value of process.exitCode or 1.

Configuration options

Config options can be passed into the registerCrashHandler function as an object with any of the keys below.

registerCrashHandler({
    // Config options go here
});

options.logger

A logger object which implements two methods, error and warn, which have the following permissive signature:

type LogMethod = (...logData: any) => any;

This is passed directly onto the relevant log-error method, see the documentation for that package for more details.

options.process

The Node.js Process object to bind the error handling event to. You may use this if you are using a child process or want to mock the process object in your tests.

registerCrashHandler({
    process: myProcessObject
});

Compatibility

Migrating from Sentry

The Reliability Kit crash handler is a replacement for Sentry's uncaught exception handling, which your app is likely to be using. You'll need to migrate away from Sentry in order to use this module. We maintain a migration guide for this on Confluence.

Migrating

Consult the Migration Guide if you're trying to migrate to a later major version of this package.

Contributing

See the central contributing guide for Reliability Kit.

License

Licensed under the MIT license. Copyright © 2022, The Financial Times Ltd.