[wrangler] fix: handle deleted entry point during hot-reload without unhandled rejection#13838
Conversation
🦋 Changeset detectedLatest commit: bfd2ac8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
There was a problem hiding this comment.
Pull request overview
This PR improves wrangler dev hot-reload resilience by preventing a synchronous readFileSync() failure (when the worker entrypoint is deleted/moved between rebuilds) from being promoted into an unhandled promise rejection that crashes the process.
Changes:
- Wraps
readFileSync(previousBundle.path, "utf8")in atry/catchduring rebuild updates and logs a warning on failure. - Skips applying the rebuild update when the entrypoint can’t be read (intended to keep the dev session alive).
- Adds a changeset to ship the fix as a patch release.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
packages/wrangler/src/dev/use-esbuild.ts |
Adds error handling + warning log around reading the previous bundle entrypoint during rebuild updates. |
.changeset/fix-unhandled-rejection-esbuild-entry-deleted.md |
Declares a patch changeset describing the dev hot-reload crash fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| entrypointSource = readFileSync(previousBundle.path, "utf8"); | ||
| } catch (e) { | ||
| // Entry point was deleted or moved between builds — skip this update. | ||
| logger.warn( |
There was a problem hiding this comment.
Valid concern. logger.once does not exist in this codebase. Repeated warnings will surface the issue to the developer without crashing the session. A deduplication helper can be added as a follow-up if the spam proves problematic in practice.
There was a problem hiding this comment.
logger.once.warn() does exist in this codebase, might be a good option here
… mutation on failure
|
@NuroDev @penalosa @dario-piotrowicz — all Copilot review comments have been addressed. This PR is ready for review. |
| entrypointSource = readFileSync(previousBundle.path, "utf8"); | ||
| } catch (e) { | ||
| // Entry point was deleted or moved between builds — skip this update. | ||
| logger.warn( |
There was a problem hiding this comment.
logger.once.warn() does exist in this codebase, might be a good option here
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
Fixes #13122.
During
wrangler dev, if the worker entry point is deleted or moved between builds, thereadFileSynccall inside theupdateBundlecallback throws synchronously and is promoted to an unhandled promise rejection, crashing the process.Fix: Wrap the
readFileSynccall in a try/catch. On failure, log a warning and return the previous bundle unchanged, so the dev session stays alive.