# babel-plugin-catch-logger

> A babel plugin that automatically reports errors in your program

Latest version **0.1.13** (published 2023-07-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-catch-logger
pnpm add babel-plugin-catch-logger
yarn add babel-plugin-catch-logger
bun add babel-plugin-catch-logger
```

## 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.13 |
| Published | 2023-07-18 |
| First published | 2023-07-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Levi Wong |
| Maintainers | workboring |
| Keywords | babel, catch, sentry, report |

## Links

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

## Dependencies (3)

- [@babel/types](https://npm.io/package/@babel/types.md) ^7.12.7
- [babel-template](https://npm.io/package/babel-template.md) ^6.26.0
- [@babel/helper-plugin-utils](https://npm.io/package/@babel/helper-plugin-utils.md) ^7.10.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.1.13 (latest) — 2023-07-18
- 0.1.12 — 2023-07-12
- 0.1.11 — 2023-07-12
- 0.1.10 — 2023-07-12
- 0.1.9 — 2023-07-12
- 0.1.8 — 2023-07-12
- 0.1.7 — 2023-07-12
- 0.1.6 — 2023-07-12
- 0.1.5 — 2023-07-12
- 0.1.4 — 2023-07-12

## README

# babel-plugin-catch-logger

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-logger",
            {
                "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)
    })
```

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