Skip to content

[wrangler] fix: handle deleted entry point during hot-reload without unhandled rejection#13838

Open
matingathani wants to merge 3 commits intocloudflare:mainfrom
matingathani:fix/unhandled-rejection-esbuild-entry-deleted
Open

[wrangler] fix: handle deleted entry point during hot-reload without unhandled rejection#13838
matingathani wants to merge 3 commits intocloudflare:mainfrom
matingathani:fix/unhandled-rejection-esbuild-entry-deleted

Conversation

@matingathani
Copy link
Copy Markdown
Contributor

Fixes #13122.

During wrangler dev, if the worker entry point is deleted or moved between builds, the readFileSync call inside the updateBundle callback throws synchronously and is promoted to an unhandled promise rejection, crashing the process.

Fix: Wrap the readFileSync call in a try/catch. On failure, log a warning and return the previous bundle unchanged, so the dev session stays alive.


  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: internal dev-mode error handling, no user-facing API change

Copilot AI review requested due to automatic review settings May 7, 2026 00:30
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

🦋 Changeset detected

Latest commit: bfd2ac8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch

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

@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team May 7, 2026 00:31
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented May 7, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a try/catch during 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.

Comment thread packages/wrangler/src/dev/use-esbuild.ts
entrypointSource = readFileSync(previousBundle.path, "utf8");
} catch (e) {
// Entry point was deleted or moved between builds — skip this update.
logger.warn(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.once.warn() does exist in this codebase, might be a good option here

Comment thread packages/wrangler/src/dev/use-esbuild.ts
@matingathani
Copy link
Copy Markdown
Contributor Author

@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(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.once.warn() does exist in this codebase, might be a good option here

Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk May 7, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13838

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13838

miniflare

npm i https://pkg.pr.new/miniflare@13838

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13838

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13838

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13838

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13838

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13838

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@13838

wrangler

npm i https://pkg.pr.new/wrangler@13838

commit: bfd2ac8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

Unhandled rejection when worker entry point is deleted during rebuild

4 participants