fix: add .catch() guards to unguarded fire-and-forget promises#747
Open
buihongduc132 wants to merge 1 commit into
Open
fix: add .catch() guards to unguarded fire-and-forget promises#747buihongduc132 wants to merge 1 commit into
buihongduc132 wants to merge 1 commit into
Conversation
Two places where .then() was called without .catch() on fire-and-forget promises, risking unhandled rejections: 1. review.ts: detectRemoteDefaultCompareTarget() is called as a non-blocking best-effort check. If git fails or cwd is invalid, the rejection would bubble up as unhandled. 2. pi-sdk.ts: proc.exited callback cleans up state but if the process exits abnormally the promise can reject. The callback already ran in .then(), so .catch() just swallows the rejection. Integration saves (obsidian/bear/octarine) are NOT affected — they use Promise.allSettled() which already handles rejections.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two places where
.then()was called without.catch()on fire-and-forget promises, risking unhandled rejections that could crash the host process.Why
When a promise is fired and forgotten (not awaited or returned), any rejection becomes an unhandled promise rejection. In Node.js/Bun, these can terminate the process or trigger warning spam.
Changes
1.
packages/server/review.tsdetectRemoteDefaultCompareTarget()is called as a non-blocking best-effort check to auto-detect the remote default branch. If git fails (no git installed, invalid cwd, network timeout), the rejection was unhandled.Fix: Add
.catch()that swallows the error — the detection is purely cosmetic and the server should keep running fine without it.2.
packages/ai/providers/pi-sdk.tsproc.exitedfires when the Pi process dies. The.then()callback cleans up pending requests and notifies listeners. But if the process exits abnormally, the promise itself rejects — and since no one catches it, it becomes an unhandled rejection.Fix: Add
.catch()that swallows it. The cleanup already ran in.then().Not changed
Integration saves (Obsidian/Bear/Octarine) use
Promise.allSettled()which already handles rejections — no fix needed there.Testing
unguarded-promise.test.tscovering the error pathsScope
~5 LOC of actual fixes (just
.catch()additions). Zero behavior change for happy paths.