Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-catch-logger

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-catch-logger

A babel plugin that automatically reports errors in your program

  • 0.1.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
195
decreased by-34.12%
Maintainers
1
Weekly downloads
 
Created
Source

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

{
    "plugins": [
        [
            "babel-plugin-catch-logger",
            {
                "name": "Sentry",
                "source": "@sentry/node",
                "methodName": "captureException",
                "catchPromise": true,
                "namespaced": true
            }
        ]
    ]
}

src/foo.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:

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

fetch().json().then(console.log)

gets compiled to:

import * as Sentry from '@sentry/node'
fetch()
    .json()
    .then(console.log)
    .catch(function (_e) {
        Sentry.captureException(_e)
    })

Keywords

FAQs

Package last updated on 18 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc