[format-errors] Await async handlePrettyErrorRequest in fetch handler's try/catch#12756
Draft
petebacondarwin wants to merge 2 commits intomainfrom
Draft
[format-errors] Await async handlePrettyErrorRequest in fetch handler's try/catch#12756petebacondarwin wants to merge 2 commits intomainfrom
handlePrettyErrorRequest in fetch handler's try/catch#12756petebacondarwin wants to merge 2 commits intomainfrom
Conversation
…'s try/catch Add missing await on the async handlePrettyErrorRequest() call so that promise rejections are properly caught by the surrounding try/catch block. Without await, async errors would result in unhandled rejections instead of being caught — meaning the error counter wouldn't increment, Sentry wouldn't capture the exception, and users wouldn't receive the 500 JSON fallback. Also adds unit tests for handlePrettyErrorRequest and reviveError. Fixes #12755 Co-Authored-By: pbacondarwin <pete@bacondarwin.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Contributor
|
✅ All changesets look good |
@cloudflare/format-errors is a deployed Worker and changesets for it are not allowed in CI since they would trigger a deployment. Co-Authored-By: pbacondarwin <pete@bacondarwin.com>
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
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.
Fixes #12755.
handlePrettyErrorRequestis anasyncfunction returningPromise<Response>, but it was returned withoutawaitin the fetch handler's try/catch block. If the promise rejects (e.g. Youch throws asynchronously), thecatchblock never executes — the error counter doesn't increment, Sentry doesn't capture the exception, and the user sees an unhandled rejection instead of the 500 JSON fallback.The fix is a one-character change:
return handlePrettyErrorRequest(payload)→return await handlePrettyErrorRequest(payload).This PR also adds the first unit tests for this package (for both
handlePrettyErrorRequestandreviveError), along with the necessary vitest configuration.Reviewer notes:
vitest.config.mtsincludes aresolve.aliasforpromjsbecause the installed package has a brokenmainfield (lib/index.jsdoesn't exist; the actual entry isindex.jsin the package root). This alias lets Vite resolve it in tests.vitestis not explicitly listed as adevDependencyofformat-errors— it resolves from the workspace root. Worth considering whether to add it explicitly.@cloudflare/format-errorsis a deployed Worker — changesets for it are disallowed in CI as they would trigger a deployment.Suggested review focus:
promjsalias approach is acceptable vs. alternative fixes.awaitfix (handlePrettyErrorRequesttest) usesvi.doMock+ dynamicimport()to get a fresh module with a mocked Youch that rejects — confirm this correctly proves the bug scenario.Devin PR requested by @petebacondarwin
Link to Devin session: https://app.devin.ai/sessions/3ad7146985384db895a3cb4a235cd1bf