# error-first

> Convert async/await try/catch to `[error, result]`

Latest version **0.9.4** (published 2017-11-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-first
pnpm add error-first
yarn add error-first
bun add error-first
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.4 |
| Published | 2017-11-19 |
| First published | 2017-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Dale Jefferson |
| Maintainers | dalejefferson |

## Links

- npm: https://www.npmjs.com/package/error-first
- Repository: https://github.com/DaleJefferson/error-first
- Homepage: https://github.com/DaleJefferson/error-first#readme
- Issues: https://github.com/DaleJefferson/error-first/issues
- npm.io page: https://npm.io/package/error-first

## Recent versions

- 0.9.4 (latest) — 2017-11-19
- 0.9.3 — 2017-11-19
- 0.9.2 — 2017-11-19
- 0.9.0 — 2017-11-19

## README

# error-first

Convert async/await try/catch to `[error, result]`

## tl;dr

```ts
import errorFirst from 'error-first'

const [error, result] = await errorFirst(doSomething)
```

## Details

### Given an async operation
```ts
const addAsync = async (a, b) => {
    if (a == null || b == null) {
        throw 'Argument Error'
    }

    return a + b
}
```

### With error-first
```ts
import errorFirst from 'error-first'
// const errorFirst = require('error-first').default

const [error, result] = await errorFirst(addAsync(1, 2)) // [undefined, 3]
```

### With standard async/await
```ts
let result = null

try {
    result = await addAsync(1, 2)
} catch(error) {
    // Do something with error
}
```

---
_Source: https://npm.io/package/error-first · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
