From f6995b94ac183435c9a7911ac761d76080808014 Mon Sep 17 00:00:00 2001 From: Alexander Alemayhu Date: Tue, 31 Oct 2023 18:00:13 +0100 Subject: [PATCH] fix: remove Bugsnag It is causing crashes in production --- package-lock.json | 99 ------------------------- package.json | 2 - src/lib/error/CrashReporter.ts | 38 ---------- src/lib/error/getErrorReporterApiKey.ts | 3 - src/lib/error/sendError.ts | 11 +-- src/server.ts | 11 --- 6 files changed, 3 insertions(+), 161 deletions(-) delete mode 100644 src/lib/error/CrashReporter.ts delete mode 100644 src/lib/error/getErrorReporterApiKey.ts diff --git a/package-lock.json b/package-lock.json index c426158dd..b353cea2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,6 @@ "license": "MIT", "dependencies": { "@2anki/csv-to-apkg": "^1.4.4", - "@bugsnag/js": "^7.20.2", - "@bugsnag/plugin-express": "^7.19.0", "@notionhq/client": "^2.2.9", "@sendgrid/mail": "^7.7.0", "aws-sdk": "^2.1359.0", @@ -800,69 +798,6 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, - "node_modules/@bugsnag/browser": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@bugsnag/browser/-/browser-7.20.2.tgz", - "integrity": "sha512-4J4s53ZpYr3hHA+QjxUjOI6U+A8+XuUVH45UshE87Jp2Y4mV8ML2DovejqJS8J8yjdbnh2z1Wtg/v3WUNt4ayQ==", - "dependencies": { - "@bugsnag/core": "^7.19.0" - } - }, - "node_modules/@bugsnag/core": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@bugsnag/core/-/core-7.19.0.tgz", - "integrity": "sha512-2KGwdaLD9PhR7Wk7xPi3jGuGsKTatc/28U4TOZIDU3CgC2QhGjubwiXSECel5gwxhZ3jACKcMKSV2ovHhv1NrA==", - "dependencies": { - "@bugsnag/cuid": "^3.0.0", - "@bugsnag/safe-json-stringify": "^6.0.0", - "error-stack-parser": "^2.0.3", - "iserror": "0.0.2", - "stack-generator": "^2.0.3" - } - }, - "node_modules/@bugsnag/cuid": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@bugsnag/cuid/-/cuid-3.0.2.tgz", - "integrity": "sha512-cIwzC93r3PQ/INeuwtZwkZIG2K8WWN0rRLZQhu+mr48Ay+i6sEki4GYfTsflse7hZ1BeDWrNb/Q9vgY3B31xHQ==" - }, - "node_modules/@bugsnag/js": { - "version": "7.20.2", - "resolved": "https://registry.npmjs.org/@bugsnag/js/-/js-7.20.2.tgz", - "integrity": "sha512-Q08k0h0h6NFwFGkFmib39Uln2WpvJdqT1EGF1JlyYiGW03Y+VopVb9r37pZrRrN9IY08mxaIEO8la5xeaWAs6A==", - "dependencies": { - "@bugsnag/browser": "^7.20.2", - "@bugsnag/node": "^7.19.0" - } - }, - "node_modules/@bugsnag/node": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@bugsnag/node/-/node-7.19.0.tgz", - "integrity": "sha512-c4snyxx5d/fsMogmgehFBGc//daH6+4XCplia4zrEQYltjaQ+l8ud0dPx623DgJl/2j1+2zlRc7y7IHSd7Gm5w==", - "dependencies": { - "@bugsnag/core": "^7.19.0", - "byline": "^5.0.0", - "error-stack-parser": "^2.0.2", - "iserror": "^0.0.2", - "pump": "^3.0.0", - "stack-generator": "^2.0.3" - } - }, - "node_modules/@bugsnag/plugin-express": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@bugsnag/plugin-express/-/plugin-express-7.19.0.tgz", - "integrity": "sha512-2nygX1M6QgLGNLGlYArwI3RN2lL1b4MImeOH7ijGhiKdiEGEDtfnwHWoEZ9S/yBRBrA5iLXxo+agxk3RZ0NZkg==", - "dependencies": { - "iserror": "^0.0.2" - }, - "peerDependencies": { - "@bugsnag/core": "^7.0.0" - } - }, - "node_modules/@bugsnag/safe-json-stringify": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/@bugsnag/safe-json-stringify/-/safe-json-stringify-6.0.0.tgz", - "integrity": "sha512-htzFO1Zc57S8kgdRK9mLcPVTW1BY2ijfH7Dk2CeZmspTWKdKqSo1iwmqrq2WtRjFlo8aRZYgLX0wFrDXF/9DLA==" - }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", @@ -3411,14 +3346,6 @@ "node": ">=10.16.0" } }, - "node_modules/byline": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/byline/-/byline-5.0.0.tgz", - "integrity": "sha512-s6webAy+R4SR8XVuJWt2V2rGvhnrhxN+9S15GNuTK3wKPOXFF6RNc+8ug2XhH+2s4f+uudG4kUVYmYOQWL2g0Q==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -4457,14 +4384,6 @@ "is-arrayish": "^0.2.1" } }, - "node_modules/error-stack-parser": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz", - "integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==", - "dependencies": { - "stackframe": "^1.3.4" - } - }, "node_modules/es-abstract": { "version": "1.21.2", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.21.2.tgz", @@ -6562,11 +6481,6 @@ "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, - "node_modules/iserror": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/iserror/-/iserror-0.0.2.tgz", - "integrity": "sha512-oKGGrFVaWwETimP3SiWwjDeY27ovZoyZPHtxblC4hCq9fXxed/jasx+ATWFFjCVSRZng8VTMsN1nDnGo6zMBSw==" - }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -11047,14 +10961,6 @@ "node": ">=16 || 14 >=14.17" } }, - "node_modules/stack-generator": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz", - "integrity": "sha512-mwnua/hkqM6pF4k8SnmZ2zfETsRUpWXREfA/goT8SLCV4iOFa4bzOX2nDipWAZFPTjLvQB82f5yaodMVhK0yJQ==", - "dependencies": { - "stackframe": "^1.3.4" - } - }, "node_modules/stack-utils": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", @@ -11076,11 +10982,6 @@ "node": ">=8" } }, - "node_modules/stackframe": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz", - "integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==" - }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", diff --git a/package.json b/package.json index 25fc20519..20331af15 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,6 @@ "license": "MIT", "dependencies": { "@2anki/csv-to-apkg": "^1.4.4", - "@bugsnag/js": "^7.20.2", - "@bugsnag/plugin-express": "^7.19.0", "@notionhq/client": "^2.2.9", "@sendgrid/mail": "^7.7.0", "aws-sdk": "^2.1359.0", diff --git a/src/lib/error/CrashReporter.ts b/src/lib/error/CrashReporter.ts deleted file mode 100644 index b4c7bb731..000000000 --- a/src/lib/error/CrashReporter.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint-disable import/no-extraneous-dependencies */ -import Bugsnag from '@bugsnag/js'; -import BugsnagPluginExpress from '@bugsnag/plugin-express'; - -import { Express } from 'express-serve-static-core'; - -export default class CrashReporter { - /** - * Add the error handler to the Express app - * It must be called after setting up all routes. - * @param app the Express app - */ - static AddErrorHandler(app: Express) { - const middleware = Bugsnag.getPlugin('express'); - if (middleware) { - // This handles any errors that Express catches - app.use(middleware.errorHandler); - } - } - - /** - * Configure the crash reporter - * It must be called before setting any routes up. - * @param app the Express app - * @param apiKey the Bugsnag API key - */ - static Configure(app: Express, apiKey: string) { - Bugsnag.start({ - apiKey, - plugins: [BugsnagPluginExpress], - }); - - const middleware = Bugsnag.getPlugin('express'); - if (middleware) { - app.use(middleware.requestHandler); - } - } -} diff --git a/src/lib/error/getErrorReporterApiKey.ts b/src/lib/error/getErrorReporterApiKey.ts deleted file mode 100644 index 6ee2def0a..000000000 --- a/src/lib/error/getErrorReporterApiKey.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const getErrorReporterApiKey = () => { - return process.env.ERROR_REPORTER_API_KEY; -}; diff --git a/src/lib/error/sendError.ts b/src/lib/error/sendError.ts index d8db8c16b..ef084d3f7 100644 --- a/src/lib/error/sendError.ts +++ b/src/lib/error/sendError.ts @@ -1,12 +1,7 @@ -/* eslint-disable import/no-extraneous-dependencies */ -import Bugsnag from '@bugsnag/js'; - export const sendError = (error: unknown) => { if (error instanceof Error) { - if (process.env.LOCAL_DEV === 'true') { - console.error(error); - } else if (process.env.NODE_ENV === 'production') { - Bugsnag.notify(error); - } + console.error(error); + } else { + console.log('unknown error '+ error); } }; diff --git a/src/server.ts b/src/server.ts index 6d82ea975..add034c94 100644 --- a/src/server.ts +++ b/src/server.ts @@ -28,12 +28,10 @@ import favoriteRouter from './routes/FavoriteRouter'; import templatesRouter from './routes/TemplatesRouter'; import defaultRouter from './routes/DefaultRouter'; -import CrashReporter from './lib/error/CrashReporter'; import { sendError } from './lib/error/sendError'; import { isStaging } from './lib/isStaging'; import { getDatabase, setupDatabase } from './data_layer'; -import { getErrorReporterApiKey } from './lib/error/getErrorReporterApiKey'; function registerSignalHandlers(server: http.Server) { process.on('uncaughtException', sendError); process.on('SIGTERM', () => { @@ -56,11 +54,6 @@ const serve = async () => { app.use(express.json({ limit: '1000mb' }) as RequestHandler); app.use(cookieParser()); - const errorReporterApiKey = getErrorReporterApiKey(); - if (errorReporterApiKey) { - CrashReporter.Configure(app, errorReporterApiKey); - } - if (isStaging()) { app.use(morgan('combined') as RequestHandler); } @@ -98,10 +91,6 @@ const serve = async () => { } ); - if (errorReporterApiKey) { - CrashReporter.AddErrorHandler(app); - } - app.use( ( err: Error,