Skip to content

fix: improve app initialization error handling#1846

Open
cxybd wants to merge 1 commit intobytedance:mainfrom
cxybd:fix/app-initialization-error-handling
Open

fix: improve app initialization error handling#1846
cxybd wants to merge 1 commit intobytedance:mainfrom
cxybd:fix/app-initialization-error-handling

Conversation

@cxybd
Copy link
Copy Markdown

@cxybd cxybd commented Mar 13, 2026

🐛 Problem

Currently, when app initialization fails in app.whenReady(), the error is only logged to console with .catch(console.log). This causes several critical issues:

  • ❌ App continues running in an inconsistent/zombie state
  • No user feedback about the initialization failure
  • ❌ Console logs may not be visible in production builds
  • Partially initialized resources are not cleaned up
  • ❌ Difficult to debug and troubleshoot startup failures

✅ Solution

Replace the simple console.log with proper error handling that:

  1. Logs detailed error information - Full error message and stack trace for debugging
  2. Shows user-friendly error dialog - Clear message about what went wrong
  3. Exits the application cleanly - Prevents running in a broken state

📝 Changes

File: apps/ui-tars/src/main/main.ts

  • Import dialog from electron
  • Replace .catch(console.log) with comprehensive error handler
  • Log full error details (message + stack trace) for debugging
  • Display error dialog to inform users about the failure
  • Call app.quit() to exit the application safely

Code diff:

import {
  app,
  BrowserView,
  BrowserWindow,
  desktopCapturer,
+ dialog,
  ipcMain,
  session,
  WebContentsView,
  screen,
} from 'electron';

...

app
  .whenReady()
  .then(async () => {
    await initializeApp();
    logger.info('app.whenReady end');
  })
- .catch(console.log);
+ .catch((error) => {
+   // Log detailed error information
+   logger.error('Failed to initialize app:', error);
+   logger.error('Error stack:', error.stack);
+
+   // Show user-friendly error dialog
+   dialog.showErrorBox(
+     'UI-TARS Initialization Failed',
+     `Failed to start UI-TARS:\n\n${error.message}\n\nPlease check the logs for details.\n\nThe application will now exit.`
+   );
+
+   // Exit the application safely
+   app.quit();
+ });
🧪 Testing
✅ TypeScript compilation: Passes (npm run typecheck)
✅ Code style: Follows project conventions
✅ Type safety: No type errors introduced
Expected behavior:

On initialization failure, users will see a clear error dialog
Detailed logs are written for debugging
Application exits cleanly instead of running in broken state
📊 Severity & Impact
Severity: Critical (8-9/10)
Type: Error handling defect

Impact:

✅ Improves user experience - Clear error messaging instead of silent failure
✅ Enhances debuggability - Full error stack traces in logs
✅ Prevents inconsistent state - App doesn't run after initialization failure
✅ Better production stability - Proper error handling for real-world scenarios
Risk: Low

Only modifies error handling path (catch block)
Normal startup flow remains unchanged
No breaking changes
🔍 Related Issues
Fixes app running in zombie state after initialization failure.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 13, 2026

Deploy Preview for agent-tars-docs canceled.

Name Link
🔨 Latest commit 91a5779
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/69b3d77a4d2d800008ecac74

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 13, 2026

Deploy Preview for tarko canceled.

Name Link
🔨 Latest commit 91a5779
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/69b3d77ab6e4f700087ad66c

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 13, 2026

CLA assistant check
All committers have signed the CLA.

- Add error dialog to notify users when initialization fails
- Log detailed error information for debugging
- Ensure app exits cleanly on initialization failure
- Prevent app from running in inconsistent state after init errors

This fixes the issue where app.whenReady().catch(console.log) would
silently swallow initialization errors, leaving the app running in a
zombie state with no user feedback.

Changes:
- Import dialog from electron
- Replace console.log with proper error handling
- Show user-friendly error dialog with error details
- Log full error stack trace for debugging
- Call app.quit() to exit cleanly

Severity: Critical (8-9/10)
Impact: Prevents app from running in inconsistent state, improves UX
@cxybd cxybd force-pushed the fix/app-initialization-error-handling branch from 33aef95 to 91a5779 Compare March 13, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants