Registry / devops / babel-plugin-catch-logger

babel-plugin-catch-logger

JSON →
library0.1.13jsnpmunverified

A Babel plugin that automatically adds catch clauses to uncaught Promises and attaches a logging call (e.g., Sentry.captureException) to all catch blocks and .catch() handlers. Version 0.1.13 is the latest stable release. It works by injecting a configurable import for your logging service and wrapping catch clauses with a logger invocation. Differentiators: zero manual instrumentation, adds logging to existing codebases without refactoring, supports both try-catch blocks and promise chains, and allows namespace or default imports for the logging library.

npm install babel-plugin-catch-logger
INSTALL
IMPORT
SIG · BABEL-PLUGIN-CATCH
B
babel-plugin-catch-logger
devopsjavascriptv0.1.13
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin)
import catchLogger from 'babel-plugin-catch-logger'
const catchLogger = require('babel-plugin-catch-logger')
This is a Babel plugin; it is typically used via babel.config.js or .babelrc, not imported directly in application code.
Sentry
import * as Sentry from '@sentry/node'
import Sentry from '@sentry/node'
When namespaced: true, the plugin generates a namespace import (import * as). If you set namespaced: false, it uses a default import.
captureException
import { captureException } from '@sentry/node'
If methodName is 'captureException' and namespaced is false, the plugin generates a named import for that function.

Shows basic Babel configuration and how the plugin transforms uncaught Promises.

// .babelrc { "plugins": [ [ "babel-plugin-catch-logger", { "name": "Sentry", "source": "@sentry/node", "methodName": "captureException", "catchPromise": true, "namespaced": true } ] ] } // Input code (src/foo.js) export function bar() { return fetch('https://example.com').then(res => res.json()); } // Compiled output: import * as Sentry from '@sentry/node'; export function bar() { return fetch('https://example.com').then(res => res.json()).catch(function (_e) { Sentry.captureException(_e); }); }
Debug
Known issues
gotchaThe plugin adds catch clauses to ALL Promises without a catch, which may introduce side effects or duplicate error reporting if the developer already logs errors elsewhere.
fix
Review generated code and manually handle uncaught Promises in a centralized way, or disable catchPromise for specific files using a babel environment.
affects: >=0.0.1
gotchaIf namespaced is false, the plugin expects a default export from the logging library; many libraries (e.g., @sentry/node) export as namespace by default, causing a runtime error.
fix
Set namespaced: true when using libraries like @sentry/node that export named exports only; otherwise use a library with a default export.
affects: >=0.0.1
gotchaThe plugin modifies the AST significantly; it may conflict with other Babel plugins that transform Promises or try-catch blocks (e.g., babel-plugin-parameter-try-catch).
fix
Ensure the run order of plugins is correct and test for conflicts, or use a single plugin for error handling.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module '@sentry/node'
The logging library specified in 'source' is not installed.
fix
Run `npm install @sentry/node` (or the appropriate logging library).
Sentry.captureException is not a function
The logging method specified in 'methodName' does not exist on the imported module, often due to using namespaced: true with a library that does not export that method as a namespace member.
fix
Check the library's exports or set namespaced: false if the library has a default export with that method.
Unexpected token: keyword «function»
The plugin may produce invalid syntax if the input code contains non-standard JavaScript (e.g., TypeScript, JSX) not handled by Babel presets.
fix
Ensure that the appropriate Babel presets (e.g., @babel/preset-env, @babel/preset-typescript) are loaded before this plugin.
Upgrade
Version history
0.1.13latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
babel-plugin-catch-logger — npm install babel-plugin-catch-logger · libregistry