From dbfb8074fc881d44a933b4a9cbc780e9688695eb Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 27 Jun 2025 09:20:31 +0000 Subject: [PATCH] Fix EPIPE error handling in Electron AppImage - Added custom error handler for electron-unhandled to suppress EPIPE errors - Added process.stdout and process.stderr error handlers for EPIPE - EPIPE errors are common in AppImages due to console output pipe issues - App now runs cleanly without unhandled error dialogs Resolves console output errors that were causing unhandled error dialogs in the distributed AppImage while maintaining proper error logging for other types of errors. --- electron/src/index.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/electron/src/index.ts b/electron/src/index.ts index e23f2bb3..3a44468e 100644 --- a/electron/src/index.ts +++ b/electron/src/index.ts @@ -9,7 +9,32 @@ import { autoUpdater } from 'electron-updater'; import { ElectronCapacitorApp, setupContentSecurityPolicy, setupReloadWatcher } from './setup'; // Graceful handling of unhandled errors. -unhandled(); +unhandled({ + logger: (error) => { + // Suppress EPIPE errors which are common in AppImages due to console output issues + if (error.message && error.message.includes('EPIPE')) { + return; // Don't log EPIPE errors + } + console.error('Unhandled error:', error); + } +}); + +// Handle EPIPE errors on stdout/stderr to prevent crashes +process.stdout.on('error', (err) => { + if (err.code === 'EPIPE') { + // Ignore EPIPE errors on stdout + return; + } + console.error('stdout error:', err); +}); + +process.stderr.on('error', (err) => { + if (err.code === 'EPIPE') { + // Ignore EPIPE errors on stderr + return; + } + console.error('stderr error:', err); +}); // Define our menu templates (these are optional) const trayMenuTemplate: (MenuItemConstructorOptions | MenuItem)[] = [new MenuItem({ label: 'Quit App', role: 'quit' })];