Skip to content

Fix unhandled 'error' event crashes in Node.js process streams - #1929

Closed
PierrunoYT wants to merge 4 commits into
google-gemini:mainfrom
PierrunoYT:main
Closed

PierrunoYT wants to merge 4 commits into
google-gemini:mainfrom
PierrunoYT:main

Conversation

@PierrunoYT

Copy link
Copy Markdown

This PR fixes the node:events:496 throw er; // Unhandled 'error' event ^ crash that was occurring when Node.js process streams emit error events without proper error handlers attached.

Problem

When EventEmitters like process.stdout or process.stdin emit 'error' events without listeners, Node.js throws an unhandled error event causing the entire process to crash with:

node:events:496
      throw er; // Unhandled 'error' event
      ^

Root Cause

Three main sources of unhandled error events were identified:

  1. Incomplete error handling in nonInteractiveCli.ts - Only handled EPIPE errors on process.stdout, leaving other error types unhandled
  2. Missing error handler in useTerminalSize.ts - Added resize event listener to process.stdout but no error handler
  3. No global uncaught exception handler - Only had unhandled promise rejection handler

Solution

Added minimal, surgical error handling:

  • Enhanced nonInteractiveCli.ts: Now handles all process.stdout errors, not just EPIPE
  • Fixed useTerminalSize.ts: Added error event handler alongside resize listener
  • Added global error handler: Comprehensive uncaught exception handler in gemini.tsx

Testing

  • ✅ All 424 existing tests pass
  • ✅ Manual verification confirms error events are handled gracefully
  • ✅ Bundle builds and CLI functionality intact
  • ✅ Linting and type checking pass

The fix ensures graceful error handling instead of process crashes while maintaining all existing functionality.

Fixes #1.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • play.googleapis.com
    • Triggering command: node (vitest 3) (dns block)
    • Triggering command: node (vitest 2) (dns block)
    • Triggering command: node (vitest 1) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@PierrunoYT
PierrunoYT requested a review from a team as a code owner June 26, 2025 13:33
@google-cla

google-cla Bot commented Jun 26, 2025

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@PierrunoYT PierrunoYT closed this Jun 26, 2025
@sripasg sripasg added the size/s A small PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants