# babel-plugin-onerror

> Experimental plugin for exception collection via babel

Latest version **0.1.0** (published 2018-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-onerror
pnpm add babel-plugin-onerror
yarn add babel-plugin-onerror
bun add babel-plugin-onerror
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-10-17 |
| First published | 2018-10-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 158.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | bobi |
| Maintainers | huangteng |
| Keywords | babel, trycatch, promise, error |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-onerror
- Repository: https://github.com/cbbfcd/babel-plugin-onerror
- Homepage: https://github.com/cbbfcd/babel-plugin-onerror#readme
- Issues: https://github.com/cbbfcd/babel-plugin-onerror/issues
- npm.io page: https://npm.io/package/babel-plugin-onerror

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

- 0.1.0 (latest) — 2018-10-17

## README

# babel-plugin-onerror

> The project is experimental in nature, with a unified, automated anomaly capture and reporting scheme

> under develop!

> inspired by [jacksky007](https://myslide.cn/slides/1031)


Front-end engineers need to quickly and accurately locate the exception code, so we need a front-end anomaly monitoring system.

We have some options:

1. window.onerror

  Global interception is not reliable, such as "Script Error".
  
  Fortunately, we can solve this problem through a cross-domain solution

  ```js
  <script crossorigin src='...'></script>
  //Access-Control-Allow-Origin: '*'
  ```

2. try...catch...  or promise().catch()

   The exception log report can be finely controlled. The problem is that the error stack information is not uniform. 
   
   For asynchronous methods, because the execution stack is different, it is impossible to catch exceptions (trycatch), etc.
  
3. ...

## about

so there a cool plan:

babel!

Babel contains a loc information, including the line number and column number.

we can wrap a unified exception information, including function name, file name, error information, line number, column number, and more... 

```js
{
  row: 12,
  col: 34,
  fileName: 'xxx.js',
  functionName: 'xxx',
  error: {
    ...
  }
}
```

automatic function at compile stage The package is flexibly controlled by a symbol such as /\*nocatch\*/.

```js
const test = () => {
  console.log('hello world!')
}
```

will be converted into:

```js
const test = () => {
  try{
    console.log('hello world!')
  }catch(e){
    someReporter(e)
  }
}
```

if you code like this, it's not work. so more flexible!

```js
const test /*nocatch*/ = () => {...} // will not be converted
```

## end

These are the things the project is doing, and of course there are a lot of imperfections that need everyone's help to guide.

I will continue to improve the project and add the test code

## features

- [x] support flexible /\*no-?catch\*/i! 

## todos

- [ ] Performance issues with try...catch..

- [ ] File size will increase 5%-15%

- [ ] promise

- [ ] react or vue ...

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