Socket
Book a DemoInstallSign in
Socket

neverpanic

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

neverpanic

This is the next generation of error handling in JavaScript. How many times have you gotten out of bed, ready to get on with your day, only to find that you have 1243 Sentry alerts because you forgot to gracefuly handle an exception in your NodeJS backend

latest
Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
666
33200%
Maintainers
1
Weekly downloads
 
Created
Source

neverpanic

This is the next generation of error handling in JavaScript. How many times have you gotten out of bed, ready to get on with your day, only to find that you have 1243 Sentry alerts because you forgot to gracefuly handle an exception in your NodeJS backend. The truth is, these are not exceptions, these are panics. Panics not just in your code, but also to your mental health.

Try neverpanic, and live a zen life.

Examples

safeFn

Create a safe function from an unsafe one:

  • Ensures that only a Result can be returned
  • Catches and returns any unexpected errors as a Result
const getUser = n.safeFn(
    async (id: string) => {
        const res = await fetch(`https://example.com/users/${id}`);
        if (!res.ok) return { success: false, error: "FAILED_TO_FETCH" };

        return { success: true, data: await res.json() };
    },
    (err) => "FAILED_TO_GET_USER",
);

const getUserResult = await getUser("some-user-id");
if (!getUserResult.success) {
    console.error(getUserResult.error);
} else {
    console.log(getUserResult.data);
}

fromUnsafe

Runs the provided callback function, catching any thrown errors and returning a Result

const user = await n.fromUnsafe(
    () => db.findUser("some-user-id"),
    (err) => "FAILED_T0_FIND_USER",
);
if (!user.success) {
    console.error(user.error);
} else {
    console.log(user.data);
}

FAQs

Package last updated on 11 Nov 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts