fix: mostrar errores fatales de arranque en producción (#22)

This commit is contained in:
Pandipipas
2026-02-19 14:37:50 +01:00
committed by GitHub
parent 182231723c
commit 95a8cc390c
+32 -2
View File
@@ -1,4 +1,4 @@
import { app, BrowserWindow, BrowserWindowConstructorOptions, shell } from "electron";
import { app, BrowserWindow, BrowserWindowConstructorOptions, dialog, shell } from "electron";
import { ChildProcess, spawn } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
@@ -344,6 +344,28 @@ function log(...args: unknown[]): void {
console.log("[scoreko-electron]", ...args);
}
function formatErrorMessage(error: unknown): string {
if (error instanceof Error) {
const stack = error.stack?.trim();
return stack && stack.length > 0 ? stack : error.message;
}
return String(error);
}
function showFatalError(message: string, error?: unknown): void {
const formattedError = error ? formatErrorMessage(error) : undefined;
const details = formattedError ? `${message}\n\n${formattedError}` : message;
console.error(details);
if (!app.isReady()) {
return;
}
dialog.showErrorBox("Scoreko - Error al iniciar", details);
}
function getOptionalEnv(name: string): string | undefined {
const value = process.env[name]?.trim();
return value && value.length > 0 ? value : undefined;
@@ -380,7 +402,7 @@ app.on("ready", () => {
}
launch().catch(async (error: unknown) => {
console.error("Failed to launch Scoreko wrapper", error);
showFatalError("No se pudo iniciar Scoreko.", error);
closeLoadingWindow();
app.exit(1);
});
@@ -420,3 +442,11 @@ app.on("will-quit", () => {
process.on("exit", () => {
stopNodeCG();
});
process.on("uncaughtException", (error) => {
showFatalError("Error inesperado en el proceso principal de Electron.", error);
});
process.on("unhandledRejection", (reason) => {
showFatalError("Promesa no controlada en el proceso principal de Electron.", reason);
});