# gerror

> Mixer for gRPC Error & ECMAScript Error

Latest version **1.0.16** (published 2021-11-24) · Apache-2.0 license · 0 weekly downloads

## Install

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

## 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 | 1.0.16 |
| Published | 2021-11-24 |
| First published | 2021-10-31 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 118.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Huan LI |
| Maintainers | zixia |
| Keywords | error, grpc, ecma, status, protocol buffer |

## Links

- npm: https://www.npmjs.com/package/gerror
- Repository: https://github.com/huan/gerror
- Homepage: https://github.com/huan/gerror#readme
- Issues: https://github.com/huan/gerror/issues
- npm.io page: https://npm.io/package/gerror

## 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

- 1.0.16 (latest) — 2021-11-24
- 0.2.3 (next) — 2021-10-31
- 1.0.14 — 2021-11-15
- 1.0.13 — 2021-11-15
- 1.0.12 — 2021-11-15
- 1.0.10 — 2021-11-15
- 1.0.11 — 2021-11-15
- 1.0.9 — 2021-11-15
- 1.0.8 — 2021-11-11
- 1.0.7 — 2021-11-11
- 1.0.6 — 2021-11-06
- 1.0.4 — 2021-11-02
- 1.0.2 — 2021-11-01
- 1.0.1 — 2021-11-01
- 0.2.4 — 2021-10-31
- … 1 more at https://npm.io/package/gerror/versions

## README

# GError

[![NPM Version](https://badge.fury.io/js/gerror.svg)](https://badge.fury.io/js/gerror)
[![NPM](https://github.com/huan/gerror/workflows/NPM/badge.svg)](https://github.com/huan/gerror/actions?query=workflow%3ANPM)
[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-blue.svg)](https://www.typescriptlang.org/)
[![ES Modules](https://img.shields.io/badge/ES-Modules-brightgreen)](https://github.com/Chatie/tsconfig/issues/16)

Mixer of gRPC Error &amp; ECMAScript Error

![GError](docs/images/gerror-logo.png)

## Motivation

We are writing async programs with gRPC with Node.js(ECMAScript) so we need to mix gRPC Error &amp; ECMAScript Error.

In order to make it easy, we build GError module

## Features

1. `GError.from(anyting: any)`
1. `gerror.toJSON()`

## Examples

TBW

## API Reference

### `class GError`

`GError` can be used to replace the standard `Error` as a drop in replacement.

```ts
import { GError } from 'gerror'

const gerror = GError.from(new Error('test'))
```

### `GError.stringify(e: any)`

Convert anything to a `JSON.stringify()`-ed `GError` payload

```ts
GError.stringify('this is a string error')

// It acepts any type of args
GError.stringify(new Error() as unknown)
```

### `wrapAsyncError()`

It has been designed to convert a Async to Sync, for example:

1. `async (...args: any[]) => Promise<any>` will be converted to `(...args: any[]) => void`
1. `Promise<any>` will be converted to `void`

The error will be send via the `onError` callback.

```ts
import { wrapAsyncError } from 'gerror'

const onError = (e: any) => console.error(e)
const wrapAsync = wrapAsyncError(onError)

const asyncFunc = async () => Promise.reject('rejection')
const syncFunc = wrapAsync(asyncFunc)
// ReturnType<typeof syncFunc> === 'void'

asyncFunc() // <- nothing happens (no unhandled rejections)
// console.error('Rejection')
```

## Resources

1. [Google Cloud APIs - Errors](https://cloud.google.com/apis/design/errors)

## History

### master v1.0 (Oct 30, 2021)

1. Initial code from `wechaty-puppet` module
1. Add `timeoutPromise()` function

## Author

[Huan LI](https://github.com/huan) ([李卓桓](http://linkedin.com/in/zixia)), Google Developer Export (GDE), zixia@zixia.net

[![Profile of Huan LI (李卓桓) on StackOverflow](https://stackexchange.com/users/flair/265499.png)](https://stackexchange.com/users/265499)

## Copyright & License

* Docs released under Creative Commons
* Code released under the Apache-2.0 License
* Code & Docs © 2021 Huan LI \<zixia@zixia.net\>

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