From fd16768945e2801e2d9fb3cd484d372a835a86ef Mon Sep 17 00:00:00 2001 From: sudipnext Date: Sun, 12 Apr 2026 19:33:40 +0545 Subject: [PATCH] refactor: remove Sentry test error handling from main and renderer processes --- electron/app/main.ts | 5 +- electron/app/preloads/index.ts | 3 - electron/app/preloads/sentry.ts | 9 - electron/app/sentry/main.ts | 9 - electron/servers/fastapi/api/main.py | 5 - .../(dashboard)/settings/PrivacySettings.tsx | 94 ------- .../app/api/sentry-example-api/route.ts | 16 -- .../nextjs/app/sentry-example-page/page.tsx | 237 ------------------ electron/servers/nextjs/types/global.d.ts | 2 - 9 files changed, 1 insertion(+), 379 deletions(-) delete mode 100644 electron/servers/nextjs/app/api/sentry-example-api/route.ts delete mode 100644 electron/servers/nextjs/app/sentry-example-page/page.tsx diff --git a/electron/app/main.ts b/electron/app/main.ts index 7cbe3b5b..13cc097e 100644 --- a/electron/app/main.ts +++ b/electron/app/main.ts @@ -16,7 +16,7 @@ import { getPuppeteerExecutablePath, isChromeInstalled } from "./utils/puppeteer import { getLiteParseRunnerPath } from "./utils/liteparse-check"; import { getImageMagickBinaryPath, isImageMagickInstalled } from "./utils/imagemagick-check"; import { startUpdateChecker, stopUpdateChecker } from "./utils/update-checker"; -import { captureMainSentryTestError, initMainSentry } from "./sentry/main"; +import { initMainSentry } from "./sentry/main"; var win: BrowserWindow | undefined; @@ -31,9 +31,6 @@ const startupStatus: Record = { // Allow renderer to query initial startup status as soon as it loads. ipcMain.handle("startup:get-status", () => startupStatus); -ipcMain.handle("sentry:test-main-error", (_event, message?: string) => { - return captureMainSentryTestError(message); -}); initMainSentry(); diff --git a/electron/app/preloads/index.ts b/electron/app/preloads/index.ts index f1d10378..3a0ac48f 100644 --- a/electron/app/preloads/index.ts +++ b/electron/app/preloads/index.ts @@ -1,5 +1,4 @@ import { contextBridge, ipcRenderer } from 'electron'; -import { captureRendererSentryTestError } from './sentry'; contextBridge.exposeInMainWorld('env', { NEXT_PUBLIC_FAST_API: process.env.NEXT_PUBLIC_FAST_API || '', @@ -36,6 +35,4 @@ contextBridge.exposeInMainWorld('electron', { onStartupStatus: (callback: (payload: { name: string; status: string }) => void) => ipcRenderer.on("startup:status", (_event, payload) => callback(payload)), getStartupStatus: () => ipcRenderer.invoke("startup:get-status"), - captureSentryRendererTestError: (message?: string) => captureRendererSentryTestError(message), - captureSentryMainTestError: (message?: string) => ipcRenderer.invoke("sentry:test-main-error", message), }); diff --git a/electron/app/preloads/sentry.ts b/electron/app/preloads/sentry.ts index d7859285..8d5d143b 100644 --- a/electron/app/preloads/sentry.ts +++ b/electron/app/preloads/sentry.ts @@ -74,13 +74,4 @@ export function initRendererSentry(): void { Sentry.setTag('process.type', 'renderer'); } -export function captureRendererSentryTestError(message?: string): string | null { - if (!isSentryInitialized) { - return null; - } - - const error = new Error(message || 'Sentry test error in renderer process'); - return Sentry.captureException(error); -} - initRendererSentry(); diff --git a/electron/app/sentry/main.ts b/electron/app/sentry/main.ts index 8dfef3b0..b7518e79 100644 --- a/electron/app/sentry/main.ts +++ b/electron/app/sentry/main.ts @@ -81,12 +81,3 @@ export function initMainSentry(): void { console.error("[Sentry] Failed to initialize in Electron main process:", error); } } - -export function captureMainSentryTestError(message?: string): string | null { - if (!isSentryInitialized) { - return null; - } - - const error = new Error(message || "Sentry test error in main process"); - return Sentry.captureException(error); -} diff --git a/electron/servers/fastapi/api/main.py b/electron/servers/fastapi/api/main.py index a60e1105..e9858520 100644 --- a/electron/servers/fastapi/api/main.py +++ b/electron/servers/fastapi/api/main.py @@ -83,8 +83,3 @@ app.add_middleware( ) app.add_middleware(UserConfigEnvUpdateMiddleware) - - -@app.get("/sentry-debug") -async def trigger_error(): - return {"division_by_zero": 1 / 0} diff --git a/electron/servers/nextjs/app/(presentation-generator)/(dashboard)/settings/PrivacySettings.tsx b/electron/servers/nextjs/app/(presentation-generator)/(dashboard)/settings/PrivacySettings.tsx index 6955f048..c16e5f84 100644 --- a/electron/servers/nextjs/app/(presentation-generator)/(dashboard)/settings/PrivacySettings.tsx +++ b/electron/servers/nextjs/app/(presentation-generator)/(dashboard)/settings/PrivacySettings.tsx @@ -2,17 +2,11 @@ import React, { useEffect, useState } from "react"; import { Switch } from "@/components/ui/switch"; import { setTelemetryEnabled } from "@/utils/mixpanel"; -import { getFastAPIUrl } from "@/utils/api"; import { Loader2 } from "lucide-react"; -import { Button } from "@/components/ui/button"; -import { notify } from "@/components/ui/sonner"; const PrivacySettings = () => { const [trackingEnabled, setTrackingEnabled] = useState(null); const [saving, setSaving] = useState(false); - const [testingMainSentry, setTestingMainSentry] = useState(false); - const [testingNextjsSentry, setTestingNextjsSentry] = useState(false); - const [testingFastapiSentry, setTestingFastapiSentry] = useState(false); useEffect(() => { async function fetchStatus() { @@ -58,73 +52,6 @@ const PrivacySettings = () => { } }; - const handleSentryMainTest = async () => { - if (!window.electron?.captureSentryMainTestError) { - notify.error( - "Sentry test unavailable", - "Electron preload API is missing. Restart the desktop app and try again.", - ); - return; - } - - setTestingMainSentry(true); - try { - const eventId = await window.electron.captureSentryMainTestError("test error"); - if (eventId) { - notify.success( - "Sentry test sent", - `Main process test event submitted. Event ID: ${eventId}`, - ); - } else { - notify.info( - "Sentry test attempted", - "No event ID returned. Check main-process Sentry initialization logs.", - ); - } - } catch (error) { - const message = - error instanceof Error ? error.message : "Could not send Sentry test event."; - notify.error("Sentry test failed", message); - } finally { - setTestingMainSentry(false); - } - }; - - const handleSentryNextjsTest = async () => { - setTestingNextjsSentry(true); - try { - await fetch("/api/sentry-example-api", { cache: "no-store" }); - notify.info( - "Next.js test triggered", - "If Sentry is configured, the Next.js API error event should appear shortly.", - ); - } catch (error) { - const message = - error instanceof Error ? error.message : "Could not call Next.js Sentry test route."; - notify.error("Next.js test failed", message); - } finally { - setTestingNextjsSentry(false); - } - }; - - const handleSentryFastapiTest = async () => { - setTestingFastapiSentry(true); - try { - const baseUrl = getFastAPIUrl(); - await fetch(`${baseUrl}/sentry-debug`, { cache: "no-store" }); - notify.info( - "FastAPI test triggered", - "If Sentry is configured, the FastAPI error event should appear shortly.", - ); - } catch (error) { - const message = - error instanceof Error ? error.message : "Could not call FastAPI Sentry test route."; - notify.error("FastAPI test failed", message); - } finally { - setTestingFastapiSentry(false); - } - }; - if (trackingEnabled === null) { return (
@@ -170,27 +97,6 @@ const PrivacySettings = () => {
- -
-

- Sentry Integration Test -

-

- Trigger test failures from Electron main, Next.js, and FastAPI to verify - all Sentry pipelines are reporting events. -

-
- - - -
-
); }; diff --git a/electron/servers/nextjs/app/api/sentry-example-api/route.ts b/electron/servers/nextjs/app/api/sentry-example-api/route.ts deleted file mode 100644 index 7fb4f565..00000000 --- a/electron/servers/nextjs/app/api/sentry-example-api/route.ts +++ /dev/null @@ -1,16 +0,0 @@ -import * as Sentry from "@sentry/nextjs"; - -class SentryExampleAPIError extends Error { - constructor(message: string | undefined) { - super(message); - this.name = "SentryExampleAPIError"; - } -} - -// A faulty API route to test Sentry's error monitoring -export function GET() { - Sentry.logger.info("Sentry example API called"); - throw new SentryExampleAPIError( - "This error is raised on the backend called by the example page.", - ); -} diff --git a/electron/servers/nextjs/app/sentry-example-page/page.tsx b/electron/servers/nextjs/app/sentry-example-page/page.tsx deleted file mode 100644 index 4ca3e103..00000000 --- a/electron/servers/nextjs/app/sentry-example-page/page.tsx +++ /dev/null @@ -1,237 +0,0 @@ -"use client"; - -import * as Sentry from "@sentry/nextjs"; -import Head from "next/head"; -import { useEffect, useState } from "react"; - -class SentryExampleFrontendError extends Error { - constructor(message: string | undefined) { - super(message); - this.name = "SentryExampleFrontendError"; - } -} - -export default function Page() { - const [hasSentError, setHasSentError] = useState(false); - const [isConnected, setIsConnected] = useState(true); - - useEffect(() => { - Sentry.logger.info("Sentry example page loaded"); - async function checkConnectivity() { - const result = await Sentry.diagnoseSdkConnectivity(); - setIsConnected(result !== "sentry-unreachable"); - } - checkConnectivity(); - }, []); - - return ( -
- - sentry-example-page - - - -
-
- - - -

sentry-example-page

- -

- Click the button below, and view the sample error on the Sentry{" "} - - Issues Page - - . For more details about setting up Sentry,{" "} - - read our docs - - . -

- - - - {hasSentError ? ( -

Error sent to Sentry.

- ) : !isConnected ? ( -
-

- It looks like network requests to Sentry are being blocked, which - will prevent errors from being captured. Try disabling your - ad-blocker to complete the test. -

-
- ) : ( -
- )} - -
-
- - -
- ); -} diff --git a/electron/servers/nextjs/types/global.d.ts b/electron/servers/nextjs/types/global.d.ts index cc78f610..e810f145 100644 --- a/electron/servers/nextjs/types/global.d.ts +++ b/electron/servers/nextjs/types/global.d.ts @@ -33,8 +33,6 @@ interface ElectronAPI { hasRequiredKey: () => Promise<{ hasKey: boolean }>; telemetryStatus: () => Promise<{ telemetryEnabled: boolean }>; getTemplates: () => Promise>; - captureSentryRendererTestError: (message?: string) => Promise | string | null; - captureSentryMainTestError: (message?: string) => Promise; } interface Window {