Socket
Socket
Sign inDemoInstall

dontpanic

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dontpanic

I see that you are having a difficult time, let me help you.


Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

🚯 dontpanic

Write robust programs instead.

npm package Build Status Code Coverage Commitizen Friendly Semantic Release

Introduction

Humans are known to panic. This is widely considered bad design.

function eat(f: string) {
  if (f === '🌯') ...
  else throw; // panic
}

Panic is not useful™️. What's useful is a thorough assessment of the circumstances. dontpanic brings you blazingly steadfast abstractions that help you recover from failure and guide your code to success.

DontPanic(eat)('🌯').onSuccess(sleep).onFailure(getPizza); // 🍕 Don't panic

Principles

🚯 No littering

throw panics your program and sends it into an unrecoverable state. Most failures should be recoverable.

throw new Error('Invalid input'); // 🚯 Crash risk

return Failed('Invalid input'); // 🛣  No crash risk

99.9% of the time there is no need to panic.

⚠️ Explicit content

It's easy to be implicit when handling exceptions. For example, a throwable function does not show that in its type signature. What happens in the success and the failure case is often hidden beneath layers of cognition, which leads to more unhandled errors and bugs.

const parsed = JSON.parse(input); // ⚠️ May panic

DontPanic(JSON.parse)(input); // ✅ Does not panic

Be explicit.

🥞 Flat as a pancake

Try/catch creates two additional execution scopes. If another failure needs to be distinguished inside those, you might need to restructure your code to favor this, or end in nesting hell. Syntax should drive you to execution flow that is easy to reason about.

try {
  const parsed = JSON.parse(input);
  try {
    const validated = validateInput(parsed);
    register(validated);
  } catch (e) {
    handleValidationError(e);
  }
} catch (e) {
  handleParsingError(e); // 🪹 Far away from home
}

DontPanic(JSON.parse)(input) // 🥞
  .onFailure(handleParsingError)
  .onSuccess(validateInput)
  .onFailure(handleValidationError)
  .onSuccess(register);

Flatten your error handling.

Install

npm install dontpanic

Usage

🅱️ This package is in beta.

Keywords

FAQs

Package last updated on 10 Nov 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc