Skip to content

fix: resolve silent crashes and add user-friendly error handling for crashes#66

Open
simrannsv wants to merge 1 commit into
snackoverflowasad:mainfrom
simrannsv:fix/connection-error-handling
Open

fix: resolve silent crashes and add user-friendly error handling for crashes#66
simrannsv wants to merge 1 commit into
snackoverflowasad:mainfrom
simrannsv:fix/connection-error-handling

Conversation

@simrannsv

Copy link
Copy Markdown

Description of Changes

This PR addresses the issue where the terminal application crashes silently or dumps raw unhandled background rejections when the WhatsApp Web connection drops or fails to initialize (e.g., when a user is offline or a session times out).

Key Adjustments:

  • Converted start() in src/bot.ts to an async method using await inside a robust try/catch block to intercept internal Puppeteer/browser navigation walls.
  • Placed top-level process event listeners (unhandledRejection and uncaughtException) at the root of the file to capture deep background leaks from node_modules.
  • Upgraded the CLI user experience with clean chalk logging alerts (Red for fatal errors, Yellow ⚠️ for warnings) providing explicit, actionable instructions on how to recover.
  • Ordered the application teardown sequentially so that process.exit() fires only after terminal logs have finished writing completely.

Related Issue Number

Fixes #43

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor or other maintenance

How Was This Tested?

Tested locally under specific failure states:

  1. Startup Isolation (Wi-Fi Off): Disconnected the network adapter and executed npm run dev. Verified that the bot intercepted Page.navigate timed out, rendered the clear troubleshooting instructions, and exited cleanly.
  2. Runtime Drop Simulation: Connected the bot successfully, then turned off Wi-Fi mid-operation. Verified the disconnected listener handled the heart-beat drop smoothly, printing recovery paths rather than cascading into an infinite loop or silent termination.
Screenshot 2026-06-20 141610

Checklist

  • The code builds without errors (npm run build).
  • Existing tests pass (npm test).
  • New tests have been added if needed.
  • Documentation has been updated to reflect these changes if needed.

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.

[BUG]: No graceful error handling when WhatsApp connection fails or times out

1 participant