Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leihuang23/babel-plugin-catch-reporter
A babel plugin that automatically reports errors in your program
https://github.com/leihuang23/babel-plugin-catch-reporter
Last synced: about 1 month ago
JSON representation
A babel plugin that automatically reports errors in your program
- Host: GitHub
- URL: https://github.com/leihuang23/babel-plugin-catch-reporter
- Owner: leihuang23
- Created: 2020-12-30T10:30:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-02T05:33:09.000Z (over 2 years ago)
- Last Synced: 2024-08-03T09:08:13.921Z (4 months ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-github-star - babel-plugin-catch-reporter
README
# babel-plugin-catch-reporter
A babel plugin that:
1. Add catch clause to your Promise if you forget to do so.
2. Add a logger to all catch clauses, whether it's a catch block or a promise `.catch()` function call.
3. Automatically import the logging service when needed.## Config:
- `name: string` - The name of the your logging service.
- `source: string` - The import path name of your logging service.
- `methodName: string` - Which logging method to invoke.
- `catchPromise: boolean` - Whether to catch promises.
- `namespaced: boolean` - Whether to import the logging service as a namespace module.## Demo
`.babelrc.json`
```json
{
"plugins": [
[
"babel-plugin-catch-reporter",
{
"name": "Sentry",
"source": "@sentry/node",
"methodName": "captureException",
"catchPromise": true,
"namespaced": true
}
]
]
}
````src/foo.js`
```js
export function noop() {
try {
return nonexistent
} catch (ignore) {
// console.log(ignore);
}
}export function bar() {
return fetch('https://google.com').json().then(console.log)
}export function baz() {
return fetch('https://google.com')
.json()
.then(console.log)
.catch((e) => {
console.error(e)
})
}
```gets compiled to:
```js
import * as Sentry from '@sentry/node'
export function noop() {
try {
return nonexistent
} catch (ignore) {
// console.log(ignore);Sentry.captureException(ignore)
}
}
export function bar() {
return fetch('https://google.com')
.json()
.then(console.log)
.catch(function (_e) {
Sentry.captureException(_e)
})
}
export function baz() {
return fetch('https://google.com')
.json()
.then(console.log)
.catch((e) => {
Sentry.captureException(e)
console.error(e)
})
}
````src/bar.js`
```js
fetch().json().then(console.log)
```gets compiled to:
```js
import * as Sentry from '@sentry/node'
fetch()
.json()
.then(console.log)
.catch(function (_e) {
Sentry.captureException(_e)
})
```