← Back to PRs

#12870: fix: recover from telegram fetch errors (issue #12835)

by ambicuity open 2026-02-09 20:42 View on GitHub →
channel: telegram stale
# Fix: Gateway crashes on Telegram fetch errors (Issue #12835) ## Description This PR fixes a bug where the gateway would crash when checking for Telegram updates if the network connection failed with a native `fetch failed` error (e.g., `TypeError: fetch failed`). Previously, the unhandled rejection handler in `src/telegram/monitor.ts` only suppressed errors that were BOTH `GrammyHttpError` AND recoverable network errors. Native fetch errors are not wrapped in `GrammyHttpError`, so they were allowed to bubble up and crash the process. This change relaxes the check to suppress **any** error that matches `isRecoverableTelegramNetworkError`, regardless of its type wrapper. ## Related Issue Fixes #12835 ## Changes - Modified `src/telegram/monitor.ts` to remove the `isGrammyHttpError` check in the unhandled rejection handler. - Removed the unused `isGrammyHttpError` helper function. ## Verification - Created a reproduction script simulating a `TypeError: fetch failed` with `ConnectTimeoutError` cause. - Verified that the new logic correctly identifies and suppresses this error. - Ran `pnpm check` and `pnpm test` to ensure no regressions. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Changes tighten gateway resilience to Telegram polling/network failures by broadening the unhandled-rejection suppression logic in `src/telegram/monitor.ts` to rely solely on `isRecoverableTelegramNetworkError` (instead of requiring a grammY `HttpError` wrapper), and removing the now-unused `isGrammyHttpError` helper. Adds a new Vitest reproduction covering a native `TypeError("fetch failed")` with a timeout-like `cause` chain to ensure the classifier recognizes this scenario. <h3>Confidence Score: 3/5</h3> - This PR is close to merge-ready but currently fails due to an incorrect/unused import in the new test and a misleading comment in the telegram monitor. - Core logic change is small and aligns with the stated bug (native fetch errors not wrapped in HttpError), but the added test imports a non-exported symbol from `src/telegram/monitor.ts`, which should cause the test suite to fail. There’s also a stale comment suggesting `HttpError` gating that no longer exists. - test/reproduce_issue_12835.ts, src/telegram/monitor.ts <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs