# bail

> Throw a given error

Latest version **2.0.2** (published 2021-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install bail
pnpm add bail
yarn add bail
bun add bail
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2021-11-07 |
| First published | 2015-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Titus Wormer |
| Maintainers | wooorm |
| Keywords | fail, bail, throw, callback, error |

## Links

- npm: https://www.npmjs.com/package/bail
- Repository: https://github.com/wooorm/bail
- Homepage: https://github.com/wooorm/bail#readme
- Issues: https://github.com/wooorm/bail/issues
- Funding: https://github.com/sponsors/wooorm
- npm.io page: https://npm.io/package/bail

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.2 (latest) — 2021-11-07
- 2.0.1 — 2021-03-26
- 2.0.0 — 2021-03-17
- 1.0.5 — 2020-01-25
- 1.0.4 — 2019-05-07
- 1.0.3 — 2018-04-16
- 1.0.2 — 2017-07-09
- 1.0.1 — 2016-07-23
- 1.0.0 — 2015-07-28

## README

# bail

[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]

Throw if given an error.

## Contents

*   [What is this?](#what-is-this)
*   [When should I use this?](#when-should-i-use-this)
*   [Install](#install)
*   [Use](#use)
*   [API](#api)
    *   [`bail(err?)`](#bailerr)
*   [Types](#types)
*   [Compatibility](#compatibility)
*   [Security](#security)
*   [Related](#related)
*   [Contribute](#contribute)
*   [License](#license)

## What is this?

This package throws a given error.

## When should I use this?

Use this package if you’re building some scripts that might theoretically get
errors but frequently don’t and you keep writing `if (error) throw error` over
and over again and you’re just really done with that.

## Install

This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:

```sh
npm install bail
```

In Deno with [Skypack][]:

```js
import {bail} from 'https://cdn.skypack.dev/bail@2?dts'
```

In browsers with [Skypack][]:

```html
<script type="module">
  import {bail} from 'https://cdn.skypack.dev/bail@2?min'
</script>
```

## Use

```js
import {bail} from 'bail'

bail()

bail(new Error('failure'))
// Error: failure
//     at repl:1:6
//     at REPLServer.defaultEval (repl.js:154:27)
//     …
```

## API

This package exports the following identifier: `bail`.
There is no default export.

### `bail(err?)`

Throw a given error (`Error?`).

## Types

This package is fully typed with [TypeScript][].
There are no extra exported types.

## Compatibility

This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.

## Security

This package is safe.

## Related

*   [`noop`][noop]
*   [`noop2`][noop2]
*   [`noop3`][noop3]

## Contribute

Yes please!
See [How to Contribute to Open Source][contribute].

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

[build-badge]: https://github.com/wooorm/bail/workflows/main/badge.svg

[build]: https://github.com/wooorm/bail/actions

[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/bail.svg

[coverage]: https://codecov.io/github/wooorm/bail

[downloads-badge]: https://img.shields.io/npm/dm/bail.svg

[downloads]: https://www.npmjs.com/package/bail

[size-badge]: https://img.shields.io/bundlephobia/minzip/bail.svg

[size]: https://bundlephobia.com/result?p=bail

[npm]: https://docs.npmjs.com/cli/install

[skypack]: https://www.skypack.dev

[license]: license

[author]: https://wooorm.com

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c

[typescript]: https://www.typescriptlang.org

[contribute]: https://opensource.guide/how-to-contribute/

[noop]: https://www.npmjs.com/package/noop

[noop2]: https://www.npmjs.com/package/noop2

[noop3]: https://www.npmjs.com/package/noop3

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