Skip to content

Commit

Permalink
Removed bugsnag
Browse files Browse the repository at this point in the history
  • Loading branch information
ron-rookout committed Jun 5, 2024
1 parent cbff791 commit 73ca654
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 699 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
},
"license": "MIT",
"devDependencies": {
"@bugsnag/core": "6.5.0",
"@material-ui/core": "^1.2.1",
"@material-ui/icons": "^1.1.0",
"@playlyfe/gql": "^2.6.0",
Expand All @@ -108,12 +107,10 @@
"tslint": "^5.10.0",
"typescript": "^5.4.3",
"webpack": "^5.91.0",
"webpack-bugsnag-plugins": "^1.4.3",
"webpack-cli": "^5.1.4",
"webpack-node-externals": "^1.7.2"
},
"dependencies": {
"@bugsnag/js": "6.5.2",
"@electron/notarize": "^2.1.0",
"@electron/remote": "2.0.10",
"@graphql-tools/schema": "^8.3.13",
Expand Down
64 changes: 2 additions & 62 deletions src/exceptionManager.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,18 @@
import { Client, INotifyOpts, NotifiableError } from "@bugsnag/core";
import {getStoreSafe} from "./explorook-store";
const bugsnag = require("@bugsnag/js");
const electron = require("electron");
const remote = process.type === "browser" || process.env.headless_mode === "true"
? electron
: require("@electron/remote");

let app: Electron.App;
// check if not running in headless mode (plain nodejs process)
if (typeof electron !== "string") {
app = electron.app || remote.app;
}

let exceptionManagerInstance: Client;

const store = getStoreSafe();

const ignoredErrors = new Set<string>(["ENOENT", "ENOTDIR", "ENOTEMPTY",
"ENOTFOUND", "ETIMEDOUT", "EACCES", "ECONNRESET"]);
Object.freeze(ignoredErrors); // prevents anyone from changing the object

export const initExceptionManager = (getUserID: () => string) => {
if (!exceptionManagerInstance && app && (app.isPackaged || process.env.headless_mode === "true")) {
const releaseStage = app.isPackaged ? "production" : "development";
exceptionManagerInstance = bugsnag({
onUncaughtException: (err: any) => {
// override default behaviour to not crash
// https://docs.bugsnag.com/platforms/javascript/configuration-options/#onuncaughtexception-node-js-only
console.log(err);
},
projectRoot: app.getAppPath(),
apiKey: "6e673fda179162f48a2c6b5d159552d2",
appType: "explorook-electron",
appVersion: app.getVersion(),
releaseStage,
beforeSend: (report: any) => {
if (getUserID) {
report.updateMetaData("user", {
userID: getUserID()
});
}
const userEmail = store.get(USER_EMAIL_KEY, null);
if (userEmail) {
report.updateMetaData("user", { userEmail });
}
}
}, null);
}
return exceptionManagerInstance;
};

export const USER_EMAIL_KEY = "userEmailKey";

export const notify = (error: NotifiableError, opts?: INotifyOpts) => {
// get the error code if exists. If no code exists then notify
const errorCode = error?.code;
if (errorCode && ignoredErrors.has(errorCode)) {
return;
}
exceptionManagerInstance?.notify(error, opts);
export const notify = (...args: any[]) => {
// This will be a NOOP until we replace Bugsnag
};

export const leaveBreadcrumb = (name: string, metaData?: any, type?: string, timestamp?: string) => {
exceptionManagerInstance?.leaveBreadcrumb(name, metaData, type, timestamp);
};

export class Logger {

public info(message?: any) {
exceptionManagerInstance?.leaveBreadcrumb("log", { message }, "info");
console.info(message);
}
public warn(message?: any) {
exceptionManagerInstance?.leaveBreadcrumb("log", { message }, "warn");
console.warn(message);
}
public error(message?: any) {
Expand Down
3 changes: 1 addition & 2 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path = require("path");
// for normalization of windows paths to linux style paths
import slash = require("slash");
import { Repository } from "./common/repository";
import { leaveBreadcrumb, notify } from "./exceptionManager";
import { notify } from "./exceptionManager";
import {getLogger} from "./logger";
import {getLibraryFolder} from "./utils";
const uuidv4 = require("uuid/v4");
Expand Down Expand Up @@ -59,7 +59,6 @@ async function getGitRootForPath(filepath: string) {
logger.debug("Getting git root for path", filepath);
return await igit.findRoot({ fs, filepath });
} catch (err) {
leaveBreadcrumb("Failed to find git root", { filepath, err });
logger.warn("Failed to find git root", { filepath, err });
// No git root was found, probably not a git repository
return null;
Expand Down
8 changes: 1 addition & 7 deletions src/index-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import _ = require("lodash");
import net = require("net");
import { basename } from "path";
import { Repository } from "./common/repository";
import { initExceptionManager, notify } from "./exceptionManager";
import { notify } from "./exceptionManager";
import {setLogLevel} from "./logger";
import { repStore } from "./repoStore";
import * as graphQlServer from "./server";
Expand All @@ -24,12 +24,6 @@ const isPortInUse = (port: number): Promise<boolean> => new Promise<boolean>((re
.listen({ port, host: "localhost" });
});

ipcRenderer.once("exception-manager-enabled-changed", (e: IpcRendererEvent, enabled: boolean) => {
if (enabled) {
initExceptionManager(() => ipcRenderer.sendSync("get-user-id"));
}
});

const onAddRepoRequest = async (fullpath: string, id?: string) => {
ipcRenderer.send("track", "repo-add-request", { fullpath });
if (!fullpath) {
Expand Down
6 changes: 1 addition & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const uuidv4 = require("uuid/v4");
import AutoLaunch = require("auto-launch");
import fetch from "node-fetch";
import {SemVer} from "semver";
import { initExceptionManager, Logger, notify } from "./exceptionManager";
import { Logger, notify } from "./exceptionManager";

initElectronRemote();
autoUpdater.logger = new Logger();
Expand Down Expand Up @@ -178,10 +178,6 @@ function main() {
userId = store.getOrCreate("user-id", uuidv4());
dataCollectionEnabled = Boolean(store.get("sentry-enabled", true));

if (dataCollectionEnabled || process.env.development) {
initExceptionManager(() => userId);
}

// listen to RPC's coming from windows
registerIpc();
// open windows (index worker and main config window)
Expand Down
12 changes: 2 additions & 10 deletions src/webapp/craco.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
const { BugsnagSourceMapUploaderPlugin } = require('webpack-bugsnag-plugins');
const package = require('../../package.json')
module.exports = {
webpack: {
configure: {
target: 'electron-renderer',
plugins: process.env.NODE_ENV === 'development' ? [] : [new BugsnagSourceMapUploaderPlugin({
apiKey: '6e673fda179162f48a2c6b5d159552d2',
publicPath: '*/app.asar/',
appVersion: package.version,
overwrite: true,
})]
target: 'electron-renderer'
}
}
}
}
1 change: 0 additions & 1 deletion src/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"private": true,
"homepage": "./",
"dependencies": {
"@bugsnag/js": "6.5.2",
"@craco/craco": "^7.1.0",
"@material-ui/core": "^4.0.0",
"isomorphic-git": "^1.8.2",
Expand Down
29 changes: 1 addition & 28 deletions src/webapp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,8 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { App } from './App';
import registerServiceWorker from './registerServiceWorker';
import bugsnag from '@bugsnag/js';
import { ipcRenderer } from 'electron';
import { app } from '@electron/remote';

// a request will be emitted from Footer.js
ipcRenderer.once("exception-manager-enabled-changed", (event, enabled) => {
if (enabled) {
console.log('enabling bugsnag on main window');
bugsnag({
onUncaughtException: (err) => {
// override default behaviour to not crash
// https://docs.bugsnag.com/platforms/javascript/configuration-options/#onuncaughtexception-node-js-only
console.log(err)
},
projectRoot: app.getAppPath(),
apiKey: '6e673fda179162f48a2c6b5d159552d2',
appType: 'explorook-react',
appVersion: app.getVersion(),
releaseStage: app.isPackaged ? 'production' : 'development',
beforeSend: report => {
report.updateMetaData("user", {
userID: ipcRenderer.sendSync("get-user-id")
});
}
});
} else {
console.log('bugsnag disabled on main window');
}
});


ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();
Loading

0 comments on commit 73ca654

Please sign in to comment.