Revert "feat(errors): fallback handlers for unhandled rejections and errors"
This reverts commit ed84b29c6b.
This commit is contained in:
+18
-31
@@ -1,41 +1,28 @@
|
|||||||
import * as Sentry from "@sentry/electron/renderer";
|
import * as Sentry from "@sentry/electron/renderer";
|
||||||
import { appConfig } from "@/config/env";
|
import { appConfig } from "@/config/env";
|
||||||
import { installErrorSinks, reportError } from "@/lib/errors";
|
import { installErrorSinks } from "@/lib/errors";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise renderer error handling. When a DSN is configured, Sentry's
|
* Initialise Sentry for a renderer process. No-ops when `sentryDsn` is empty
|
||||||
* own global handlers capture uncaught exceptions and unhandled promise
|
* so dev builds and unconfigured envs stay quiet.
|
||||||
* rejections. Otherwise we install a minimal fallback so stray rejections
|
|
||||||
* aren't silent in dev / unconfigured envs.
|
|
||||||
*/
|
*/
|
||||||
export function initSentryRenderer(): void {
|
export function initSentryRenderer(): void {
|
||||||
if (appConfig.sentryDsn) {
|
if (!appConfig.sentryDsn) return;
|
||||||
Sentry.init({
|
|
||||||
dsn: appConfig.sentryDsn,
|
|
||||||
tracesSampleRate: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
installErrorSinks({
|
Sentry.init({
|
||||||
capture: (err, context) =>
|
dsn: appConfig.sentryDsn,
|
||||||
Sentry.captureException(err, { extra: context }),
|
tracesSampleRate: 0,
|
||||||
breadcrumb: (err, context) =>
|
|
||||||
Sentry.addBreadcrumb({
|
|
||||||
category: "error",
|
|
||||||
level: "error",
|
|
||||||
message: err instanceof Error ? err.message : String(err),
|
|
||||||
data: context,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener("unhandledrejection", (event) => {
|
|
||||||
reportError(event.reason, { scope: "unhandledrejection" });
|
|
||||||
});
|
});
|
||||||
window.addEventListener("error", (event) => {
|
|
||||||
reportError(event.error ?? new Error(event.message), {
|
installErrorSinks({
|
||||||
scope: "window.error",
|
capture: (err, context) =>
|
||||||
});
|
Sentry.captureException(err, { extra: context }),
|
||||||
|
breadcrumb: (err, context) =>
|
||||||
|
Sentry.addBreadcrumb({
|
||||||
|
category: "error",
|
||||||
|
level: "error",
|
||||||
|
message: err instanceof Error ? err.message : String(err),
|
||||||
|
data: context,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+19
-28
@@ -1,39 +1,30 @@
|
|||||||
import { app } from "electron";
|
import { app } from "electron";
|
||||||
import * as Sentry from "@sentry/electron/main";
|
import * as Sentry from "@sentry/electron/main";
|
||||||
import { appConfig } from "@/config/env";
|
import { appConfig } from "@/config/env";
|
||||||
import { installErrorSinks, reportError } from "@/lib/errors";
|
import { installErrorSinks } from "@/lib/errors";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise main-process error handling. Sentry owns uncaught-exception
|
* Initialise Sentry for the main process. Captures uncaught exceptions from
|
||||||
* capture when a DSN is configured; otherwise we install a minimal Node
|
* the Node side and the crash reporter. Safe to call before `app.whenReady`.
|
||||||
* fallback so rejections aren't silent. Safe to call before `app.whenReady`.
|
|
||||||
*/
|
*/
|
||||||
export function initSentryMain(): void {
|
export function initSentryMain(): void {
|
||||||
if (appConfig.sentryDsn) {
|
if (!appConfig.sentryDsn) return;
|
||||||
Sentry.init({
|
|
||||||
dsn: appConfig.sentryDsn,
|
|
||||||
tracesSampleRate: 0,
|
|
||||||
release: app.getVersion(),
|
|
||||||
});
|
|
||||||
|
|
||||||
installErrorSinks({
|
Sentry.init({
|
||||||
capture: (err, context) =>
|
dsn: appConfig.sentryDsn,
|
||||||
Sentry.captureException(err, { extra: context }),
|
tracesSampleRate: 0,
|
||||||
breadcrumb: (err, context) =>
|
release: app.getVersion(),
|
||||||
Sentry.addBreadcrumb({
|
|
||||||
category: "error",
|
|
||||||
level: "error",
|
|
||||||
message: err instanceof Error ? err.message : String(err),
|
|
||||||
data: context,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
process.on("uncaughtException", (err) => {
|
|
||||||
reportError(err, { scope: "uncaughtException" });
|
|
||||||
});
|
});
|
||||||
process.on("unhandledRejection", (reason) => {
|
|
||||||
reportError(reason, { scope: "unhandledRejection" });
|
installErrorSinks({
|
||||||
|
capture: (err, context) =>
|
||||||
|
Sentry.captureException(err, { extra: context }),
|
||||||
|
breadcrumb: (err, context) =>
|
||||||
|
Sentry.addBreadcrumb({
|
||||||
|
category: "error",
|
||||||
|
level: "error",
|
||||||
|
message: err instanceof Error ? err.message : String(err),
|
||||||
|
data: context,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user