All Projects → nucleartide → dx

nucleartide / dx

Licence: other
JavaScript without `try...catch`.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to dx

node-graceful-shutdown
Gracefully shutdown your modular NodeJS application.
Stars: ✭ 20 (-23.08%)
Mutual labels:  error-handling
result17
A rust like Result type for modern C++
Stars: ✭ 13 (-50%)
Mutual labels:  error-handling
miette
Fancy upgrade to std::error::Error.
Stars: ✭ 945 (+3534.62%)
Mutual labels:  error-handling
safe
🛡 PHP functions smarten up to throw exceptions instead of returning false or triggering errors.
Stars: ✭ 15 (-42.31%)
Mutual labels:  error-handling
static-404
⚡️ A WordPress plugin to quickly send a 404 for missing static files
Stars: ✭ 24 (-7.69%)
Mutual labels:  error-handling
react-error-guard
⚛️An overlay for displaying stack frames based on create-react-app/packages/react-error-overlay
Stars: ✭ 18 (-30.77%)
Mutual labels:  error-handling
kotlin-multiplatform-example
A Kotlin multiplatform example app that targets Android, ReactJS, iOS, JavaFx, and Spring Boot
Stars: ✭ 115 (+342.31%)
Mutual labels:  error-handling
nuxt-winston-log
Nuxt module for logging SSR errors using winston
Stars: ✭ 41 (+57.69%)
Mutual labels:  error-handling
bugsnag
Report errors with Bugsnag 🐛
Stars: ✭ 37 (+42.31%)
Mutual labels:  error-handling
progress-bar-log
A component to display a progress bar and last X logs at the same time.
Stars: ✭ 44 (+69.23%)
Mutual labels:  error-handling
babel-errors
Nicer error messages for Babel
Stars: ✭ 15 (-42.31%)
Mutual labels:  error-handling
custom-exception-middleware
Middleware to catch custom or accidental exceptions
Stars: ✭ 30 (+15.38%)
Mutual labels:  error-handling
failure
Error management
Stars: ✭ 1,448 (+5469.23%)
Mutual labels:  error-handling
friendly-error
Show uncaught errors friendly in Node.js.
Stars: ✭ 75 (+188.46%)
Mutual labels:  error-handling
fejl
Error-making utility for Node apps.
Stars: ✭ 30 (+15.38%)
Mutual labels:  error-handling
custom error
Define custom errors without boilerplate using the custom_error! macro.
Stars: ✭ 70 (+169.23%)
Mutual labels:  error-handling
superagent-intercept
Add functions that will be called during end() e.g. for handling error conditions without having the same code all over the place.
Stars: ✭ 23 (-11.54%)
Mutual labels:  error-handling
sentry-testkit
A Sentry plugin to allow Sentry report interception and further inspection of the data being sent
Stars: ✭ 78 (+200%)
Mutual labels:  error-handling
merr
🔥 Minimal and good enough error handling library for Clojure/ClojureScript
Stars: ✭ 25 (-3.85%)
Mutual labels:  error-handling
failure
An error handling package for Go.
Stars: ✭ 24 (-7.69%)
Mutual labels:  error-handling

dx

JavaScript without try...catch.


Motivation

JavaScript expects you to handle errors with try...catch, but the syntax is somewhat inconvenient:

1. You have to declare result variables separately from your function calls.

const userInput = 'fail'

let json
try {
  json = JSON.parse(userInput)
} catch (err) {
  console.error(err.stack)
}

// Do something with `json`...

Since we declare json separately, we can't declare json as a const binding.

2. try...catch promotes catch-all error handling.

try {
  // A bunch of stuff happens...
  // ...
  // ...
} catch (err) {
  console.log('welp')
  console.error(err.stack)
}

You might want to handle errors in a more fine-grained way. But then you run into the verbosity of problem 1.


Enter dx

dx is a micro utility (it's just a few lines) that addresses the two pain points above.

import { dx } from '@nucleartide/dx'

const [res, err] = dx(JSON.parse)('invalid json')
if (err) {
  console.error(err.stack)
}

It allows you to place your declaration and function call on the same line. And it promotes a granular, per-function error handling style.

It also works with async functions:

import { dx } from '@nucleartide/dx'

function asyncHello(name) {
  return Promise.reject(`hello ${name}`)
}

;(async () => {
  const [res, err] = await dx(asyncHello)('jesse')
  if (err) {
    console.error(err.stack)
  }
})

Convinced?

npm install @nucleartide/dx

License

MIT


Jason Tu · GitHub @nucleartide · Twitter @nucleartide

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].