Skip to content

fix: preserve NonRetryableError message when compat flag is enabled#13560

Open
vaishnav-mk wants to merge 4 commits intocloudflare:mainfrom
vaishnav-mk:vaish/fix-nonretryable-error-message
Open

fix: preserve NonRetryableError message when compat flag is enabled#13560
vaishnav-mk wants to merge 4 commits intocloudflare:mainfrom
vaishnav-mk:vaish/fix-nonretryable-error-message

Conversation

@vaishnav-mk
Copy link
Copy Markdown

@vaishnav-mk vaishnav-mk commented Apr 16, 2026

Fixes the NonRetryableError message being replaced with a generic error message in local dev

When the workflows_preserve_non_retryable_error_message compatibility flag is enabled, NonRetryableError now preserves the original error name and message instead of replacing it with a generic WorkflowFatalError message


  • Tests
  • Tests included/updated
  • Automated tests not possible - manual testing has been completed as follows:
    • Tested locally with wrangler dev using local build with the compat flag enabled, error shows preserved NonRetryableError name and original message
    • Tested locally with wrangler dev using local build without the compat flag, error shows generic WorkflowFatalError message (unchanged behavior)
  • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This is behind an experimental compatibility flag (workflows_preserve_non_retryable_error_message). Docs will be added when it graduates to a compat date.

A picture of a cute animal (not mandatory, but encouraged)
image

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 16, 2026

🦋 Changeset detected

Latest commit: 9c066a0

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

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

@vaishnav-mk vaishnav-mk marked this pull request as ready for review April 16, 2026 09:39
@workers-devprod workers-devprod requested review from a team and penalosa and removed request for a team April 16, 2026 09:39
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 16, 2026

Codeowners approval required for this PR:

  • @cloudflare/workflows
  • ✅ @cloudflare/wrangler
Show detailed file reviewers
  • packages/workflows-shared/src/context.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/engine.ts: [@cloudflare/workflows]
  • packages/workflows-shared/src/lib/errors.ts: [@cloudflare/workflows]
  • packages/workflows-shared/tests/engine.test.ts: [@cloudflare/workflows]

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

Comment thread packages/workflows-shared/src/engine.ts Outdated
Comment thread packages/workflows-shared/src/engine.ts Outdated
@vaishnav-mk vaishnav-mk force-pushed the vaish/fix-nonretryable-error-message branch from cb2fa30 to 8b56879 Compare April 17, 2026 08:17
devin-ai-integration[bot]

This comment was marked as resolved.

@vaishnav-mk vaishnav-mk force-pushed the vaish/fix-nonretryable-error-message branch from 8b56879 to 396be46 Compare April 17, 2026 08:32
devin-ai-integration[bot]

This comment was marked as resolved.

@vaishnav-mk vaishnav-mk force-pushed the vaish/fix-nonretryable-error-message branch 2 times, most recently from 71252fa to 0cbbdff Compare April 17, 2026 09:06
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Looking much cleaner. It's a shame that one must pass through the compat flags but I can't think of a more straightforward approach.

Comment thread packages/workflows-shared/tests/engine.test.ts Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 17, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 0cbbdff

@penalosa penalosa removed their request for review April 17, 2026 10:43
@vaishnav-mk vaishnav-mk force-pushed the vaish/fix-nonretryable-error-message branch from 0cbbdff to 965ee4f Compare April 21, 2026 05:38
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View 7 additional findings in Devin Review.

Open in Devin Review

message: "my custom error message",
});

vi.unstubAllGlobals();
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.

🟡 Stubbed global Cloudflare leaks to subsequent tests if test fails

The test at packages/workflows-shared/tests/engine.test.ts:69 stubs globalThis.Cloudflare via vi.stubGlobal, but vi.unstubAllGlobals() is only called at line 128 at the end of the test body. If any assertion or await between lines 69-127 throws, the stub is never cleaned up. The afterEach hook (line 18) only calls workerdUnsafe.abortAllDurableObjects() — it does not unstub globals. The shared vitest config's restoreMocks: true only restores spies (.mockRestore()), not globals stubbed with vi.stubGlobal. This means subsequent tests would see a fake Cloudflare global with only workflows_preserve_non_retryable_error_message set, causing shouldPreserveNonRetryableError() to return true unexpectedly and potentially masking test failures or causing false passes.

Prompt for agents
The vi.unstubAllGlobals() call at the end of the test body (line 128) will not execute if the test throws before reaching it. Move the cleanup into an afterEach or use a try/finally block to ensure the Cloudflare global stub is always cleaned up.

Option 1: Add vi.unstubAllGlobals() to the existing afterEach hook at line 18-20.
Option 2: Wrap the test body in a try/finally with vi.unstubAllGlobals() in the finally block.
Option 3: Add unstubGlobals: true to the vitest config for this package.

Option 1 is simplest and mirrors the existing afterEach pattern.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

3 participants