{"id":19032,"library":"babel-plugin-catch-logger","title":"babel-plugin-catch-logger","description":"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.","status":"active","version":"0.1.13","language":"javascript","source_language":"en","source_url":"https://github.com/catmorphic/babel-plugin-catch-logger","tags":["javascript","babel","catch","sentry","report"],"install":[{"cmd":"npm install babel-plugin-catch-logger","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-catch-logger","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-catch-logger","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a Babel plugin; it is typically used via babel.config.js or .babelrc, not imported directly in application code.","wrong":"const catchLogger = require('babel-plugin-catch-logger')","symbol":"default (plugin)","correct":"import catchLogger from 'babel-plugin-catch-logger'"},{"note":"When namespaced: true, the plugin generates a namespace import (import * as). If you set namespaced: false, it uses a default import.","wrong":"import Sentry from '@sentry/node'","symbol":"Sentry","correct":"import * as Sentry from '@sentry/node'"},{"note":"If methodName is 'captureException' and namespaced is false, the plugin generates a named import for that function.","wrong":null,"symbol":"captureException","correct":"import { captureException } from '@sentry/node'"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\n    [\n      \"babel-plugin-catch-logger\",\n      {\n        \"name\": \"Sentry\",\n        \"source\": \"@sentry/node\",\n        \"methodName\": \"captureException\",\n        \"catchPromise\": true,\n        \"namespaced\": true\n      }\n    ]\n  ]\n}\n\n// Input code (src/foo.js)\nexport function bar() {\n  return fetch('https://example.com').then(res => res.json());\n}\n\n// Compiled output:\nimport * as Sentry from '@sentry/node';\nexport function bar() {\n  return fetch('https://example.com').then(res => res.json()).catch(function (_e) {\n    Sentry.captureException(_e);\n  });\n}","lang":"javascript","description":"Shows basic Babel configuration and how the plugin transforms uncaught Promises."},"warnings":[{"fix":"Review generated code and manually handle uncaught Promises in a centralized way, or disable catchPromise for specific files using a babel environment.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Set namespaced: true when using libraries like @sentry/node that export named exports only; otherwise use a library with a default export.","message":"If 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.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Ensure the run order of plugins is correct and test for conflicts, or use a single plugin for error handling.","message":"The 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).","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install @sentry/node` (or the appropriate logging library).","cause":"The logging library specified in 'source' is not installed.","error":"Cannot find module '@sentry/node'"},{"fix":"Check the library's exports or set namespaced: false if the library has a default export with that method.","cause":"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.","error":"Sentry.captureException is not a function"},{"fix":"Ensure that the appropriate Babel presets (e.g., @babel/preset-env, @babel/preset-typescript) are loaded before this plugin.","cause":"The plugin may produce invalid syntax if the input code contains non-standard JavaScript (e.g., TypeScript, JSX) not handled by Babel presets.","error":"Unexpected token: keyword «function»"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}