mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
fix: mostrar errores fatales de arranque en producción (#22)
This commit is contained in:
+32
-2
@@ -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 { ChildProcess, spawn } from "node:child_process";
|
||||||
import fs from "node:fs";
|
import fs from "node:fs";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
@@ -344,6 +344,28 @@ function log(...args: unknown[]): void {
|
|||||||
console.log("[scoreko-electron]", ...args);
|
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 {
|
function getOptionalEnv(name: string): string | undefined {
|
||||||
const value = process.env[name]?.trim();
|
const value = process.env[name]?.trim();
|
||||||
return value && value.length > 0 ? value : undefined;
|
return value && value.length > 0 ? value : undefined;
|
||||||
@@ -380,7 +402,7 @@ app.on("ready", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
launch().catch(async (error: unknown) => {
|
launch().catch(async (error: unknown) => {
|
||||||
console.error("Failed to launch Scoreko wrapper", error);
|
showFatalError("No se pudo iniciar Scoreko.", error);
|
||||||
closeLoadingWindow();
|
closeLoadingWindow();
|
||||||
app.exit(1);
|
app.exit(1);
|
||||||
});
|
});
|
||||||
@@ -420,3 +442,11 @@ app.on("will-quit", () => {
|
|||||||
process.on("exit", () => {
|
process.on("exit", () => {
|
||||||
stopNodeCG();
|
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);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user