Skip to content

[wrangler] Add upgrade hint to unexpected configuration field warnings#11800

Merged
petebacondarwin merged 10 commits intomainfrom
improve-unexpected-fields-warning
Mar 23, 2026
Merged

[wrangler] Add upgrade hint to unexpected configuration field warnings#11800
petebacondarwin merged 10 commits intomainfrom
improve-unexpected-fields-warning

Conversation

@southpolesteve
Copy link
Copy Markdown
Contributor

@southpolesteve southpolesteve commented Jan 5, 2026

Summary

When Wrangler encounters unexpected fields in the configuration file, users often don't know why. This PR improves the warning message to suggest updating Wrangler as a potential solution, since the field might be valid in a newer version — but only when a newer version is actually available, and only via a structured flag rather than fragile string matching.

Before:

▲ [WARNING] Processing wrangler.jsonc configuration:
    - Unexpected fields found in observability field: "tracing"

After (when a newer Wrangler version is available):

▲ [WARNING] Processing wrangler.jsonc configuration:
    - Unexpected fields found in observability field: "tracing"

There is a newer version of Wrangler available (current: 4.x.x, latest: 4.y.y). Try upgrading, as it might support this configuration option.

No hint is shown when the user is already on the latest version.

Implementation notes

  • Added hasUnexpectedFields: boolean property and hasUnexpectedFieldsInTree() recursive method to the Diagnostics class in @cloudflare/workers-utils, mirroring the existing hasErrors()/hasWarnings() pattern. This replaces the previous fragile renderWarnings().includes("Unexpected fields found") string check.
  • validateAdditionalProperties() now sets diagnostics.hasUnexpectedFields = true when unknown fields are found.
  • Extracted a shared logWarningsWithUpgradeHint() helper in wrangler/src/config/index.ts, eliminating duplication between readConfig and readPagesConfig.
  • Removed the duplicate ConfigBindingOptions type definition from wrangler/src/config/index.ts — it already exists in and is exported from @cloudflare/workers-utils.

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This is an improvement to an existing warning message

Open with Devin

@southpolesteve southpolesteve requested a review from a team as a code owner January 5, 2026 22:48
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 5, 2026

🦋 Changeset detected

Latest commit: 6e3f783

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

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Jan 5, 2026

Claude finished @southpolesteve's task —— View job


Changeset Review

✅ All changesets look good

The changeset .changeset/unexpected-fields-upgrade-hint.md has been reviewed and validated:

  • Version Type: Correctly uses patch for this bug fix/improvement to warning messages
  • Changelog Quality: Clear title and informative description explaining the change and its purpose
  • Markdown Headers: No h1/h2/h3 headers present (follows formatting rules)
  • Package Coverage: Correctly references only wrangler package

The changeset follows all guidelines from .changeset/README.md.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 5, 2026

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

wrangler

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

commit: 6e3f783

Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

I don't find "If this is a new configuration option, please update your Wrangler version." helpful.

i.e. what if not?

It could be a typo, you could already be on the latest wrangler, ...

Maybe one thing we could do instead is to validate the config against the schema and error early?

@southpolesteve
Copy link
Copy Markdown
Contributor Author

I don't find "If this is a new configuration option, please update your Wrangler version." helpful.

Alternative suggestions? Something needs to change about the current error. Its a dead end. Not clear what the fix is and we should at least guide the user in some direction. It could be other things but suggesting upgrading wrangler is not an unhelpful suggestion.

@southpolesteve southpolesteve force-pushed the improve-unexpected-fields-warning branch from 904e5cf to 92cc8f4 Compare January 6, 2026 19:00
@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jan 6, 2026

I don't find "If this is a new configuration option, please update your Wrangler version." helpful.

Alternative suggestions? Something needs to change about the current error. Its a dead end. Not clear what the fix is and we should at least guide the user in some direction. It could be other things but suggesting upgrading wrangler is not an unhelpful suggestion.

My alternative suggestion would be to validate the config against the schema and error if there is a mismatch.

IMO we should not "please update your Wrangler version" because this might not solve the issue and adding more code (that has to be maintained) for something that is not very helpful is a burden.

@vicb
Copy link
Copy Markdown
Contributor

vicb commented Jan 6, 2026

Looking at the diffs:

					    - Unexpected fields found in migrations field: \\"unrecognized_field\\"
					      If this is a new configuration option, please update your Wrangler version."

This PR is only adding noise here

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.

I think the idea of putting up a message (especially as it only happens once and only if there is a newer version of Wrangler available) is a reasonable UX improvement.

I think the message can be better - I made a suggestion.
But also I think we could/should look at doing some kind of fuzzy matching on the unexpected option like:

"Unexpected option trcing, did you mean tracing?"

@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Jan 7, 2026
@petebacondarwin
Copy link
Copy Markdown
Contributor

Triage notes (stale PR review)

The core idea (showing an upgrade hint when unexpected config fields are found) is sound, but the implementation needs rework per review feedback from @petebacondarwin and @vicb.

Required changes:

  1. Replace magic string matching with a structured flag - Instead of diagnostics.renderWarnings().includes("Unexpected fields found"), add a hasUnexpectedFields boolean to the Diagnostics class in @cloudflare/workers-utils. Set it to true when unknown fields are encountered during validation.

  2. Reword the message - Per Pete's suggestion: "There is a newer version of Wrangler available (current: X.Y.Z, latest: A.B.C). Try upgrading, as it might support this configuration option."

  3. De-duplicate with the banner - The Wrangler banner already shows "(update available X.Y.Z)". Either only show the hint when the banner doesn't appear, or clearly differentiate it as contextual advice.

  4. Extract shared helper - Don't copy-paste the check+hint block between readConfig and readPagesConfig.

  5. Resolve merge conflicts - PR is in CONFLICTING state.

Estimated effort: ~2-3 hours

@penalosa
Copy link
Copy Markdown
Contributor

/bonk can you apply the fixes mentioned in @petebacondarwin's last comment?

ask-bonk[bot]
ask-bonk bot previously requested changes Mar 20, 2026
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Review Summary

The core idea — hinting users to upgrade Wrangler when unexpected config fields are found — is a reasonable UX improvement. However, the implementation needs rework to address the feedback from @petebacondarwin and @vicb. The PR also has merge conflicts that need resolving.

Issues to address

1. Replace magic string matching with a structured flag

The current check at packages/wrangler/src/config/index.ts:93:

if (diagnostics.renderWarnings().includes("Unexpected fields found")) {

is fragile — it breaks if the warning message text is ever reworded. Both @vicb and @petebacondarwin flagged this.

Suggested fix: Add a hasUnexpectedFields boolean property to the Diagnostics class in packages/workers-utils/src/config/diagnostics.ts. Set it to true inside validateAdditionalProperties() in packages/workers-utils/src/config/validation-helpers.ts:632 when unexpected fields are detected. Then propagate it recursively (like hasErrors()/hasWarnings()). In config/index.ts, check diagnostics.hasUnexpectedFields (or a recursive getter) instead of string-matching.

// In diagnostics.ts
export class Diagnostics {
  errors: string[] = [];
  warnings: string[] = [];
  children: Diagnostics[] = [];
  hasUnexpectedFields: boolean = false;
  // ... add a recursive check method similar to hasErrors()
}

// In validation-helpers.ts, inside validateAdditionalProperties:
if (restPropSet.size > 0) {
  diagnostics.hasUnexpectedFields = true;
  // ...existing warning push...
}

// In config/index.ts:
if (diagnostics.hasUnexpectedFields) {
  void logUpdateHintIfAvailable();
}

Since Diagnostics is not currently exported from @cloudflare/workers-utils, you'd either need to export it or just rely on the structural type (the property will be accessible either way since normalizeAndValidateConfig returns it).

2. Reword the message

Per @petebacondarwin's suggestion, the message should avoid the word "new" (which is misleading if the user is on a very old version). Something like:

"There is a newer version of Wrangler available (current: X.Y.Z, latest: A.B.C). Try upgrading, as it might support this configuration option."

This is more precise and actionable.

3. De-duplicate the check between readConfig and readPagesConfig

The same check-and-hint block is copy-pasted in both functions (lines 92-95 and 164-167). Extract the warning-logging logic into a shared helper, e.g.:

function logWarningsWithUpgradeHint(diagnostics: Diagnostics) {
  logger.warn(diagnostics.renderWarnings());
  if (diagnostics.hasUnexpectedFields) {
    void logUpdateHintIfAvailable();
  }
}

Then call logWarningsWithUpgradeHint(diagnostics) in both readConfig and readPagesConfig.

4. Resolve merge conflicts

The PR is in CONFLICTING state. ConfigBindingOptions was moved to @cloudflare/workers-utils on main, so the local type definition added in this PR (lines 36-51) needs to be removed. Rebase onto current main to resolve.

5. Consider interaction with the banner

printWranglerBanner() already shows "(update available X.Y.Z)" when a newer version exists. The logUpdateHintIfAvailable() function uses the same updateCheck() call (which is memoized, so no extra network request). However, the hint message and the banner serve different purposes — the banner is a general nudge, while this hint is contextual advice tied to the specific unexpected-field warning. This is fine, but worth noting in a code comment so future maintainers understand why both exist.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 20, 2026

I've posted a review on PR #11800 requesting changes. Here's a summary of the feedback:

  1. Replace magic string matching with a structured flag — The diagnostics.renderWarnings().includes("Unexpected fields found") check is fragile. Recommended adding a hasUnexpectedFields boolean to the Diagnostics class, set it in validateAdditionalProperties(), and check that instead.

  2. Reword the message — Per Pete's earlier feedback, avoid "new" and instead say something like: "There is a newer version of Wrangler available (current: X.Y.Z, latest: A.B.C). Try upgrading, as it might support this configuration option."

  3. De-duplicate — The check+hint block is copy-pasted in both readConfig and readPagesConfig. Extract it into a shared helper function.

  4. Resolve merge conflicts — The PR is in CONFLICTING state due to ConfigBindingOptions being moved to @cloudflare/workers-utils on main.

  5. Note on banner interaction — The existing banner already shows "(update available)" via the same memoized updateCheck() call, so there's no extra cost, but a code comment explaining the intentional overlap would help future maintainers.

github run

southpolesteve and others added 7 commits March 23, 2026 11:49
When Wrangler encounters unexpected fields in the configuration file,
it now suggests updating Wrangler as a potential solution. This helps
users who may be using configuration options that were added in a
newer version of Wrangler.
When there are unexpected field warnings, also log the current wrangler
version and the latest available version (if an update is available).
This helps users know if they're behind and should upgrade.
Instead of using void with an async function (which could print after
other output or not at all), use a synchronous getter that returns
the cached latest version if the update check has already completed.
This is reliable because the banner kicks off the update check early.
The wrangler banner already shows '(update available X.X.X)' when a
newer version exists. Adding version info after the warning was
redundant. Keep only the simple hint message in the warning itself.
The indentText function in diagnostics.ts already adds 2 spaces to
continuation lines, so the source message should not have leading
spaces. This fixes the CI test failure.
Instead of always showing the upgrade hint for unexpected config fields,
only display it when we detect that a newer version of Wrangler exists.
This avoids confusing users who are already on the latest version.
- Add `hasUnexpectedFields` boolean property and `hasUnexpectedFieldsInTree()`
  recursive method to the `Diagnostics` class, mirroring `hasErrors()`
- Set `hasUnexpectedFields = true` in `validateAdditionalProperties()` instead
  of relying on magic string matching against rendered warning output
- Export `Diagnostics` class from `@cloudflare/workers-utils`
- Extract `logWarningsWithUpgradeHint()` shared helper in wrangler config,
  eliminating the copy-paste between `readConfig` and `readPagesConfig`
- Reword the hint message per Pete's suggestion: 'There is a newer version
  of Wrangler available (current: X.Y.Z, latest: A.B.C). Try upgrading,
  as it might support this configuration option.'
- Remove the locally-defined `ConfigBindingOptions` type from wrangler
  (it already exists in and is exported from `@cloudflare/workers-utils`)
- Add tests covering: hint shown when update available, hint suppressed when
  no update available, hint suppressed for non-unexpected-field warnings
@petebacondarwin petebacondarwin force-pushed the improve-unexpected-fields-warning branch from a8ceb52 to 31124e1 Compare March 23, 2026 11:49
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 23, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 23, 2026

✅ All changesets look good

@petebacondarwin petebacondarwin force-pushed the improve-unexpected-fields-warning branch from 107c5f8 to 2a2ee1d Compare March 23, 2026 11:56
@petebacondarwin petebacondarwin merged commit 875da60 into main Mar 23, 2026
45 checks passed
@petebacondarwin petebacondarwin deleted the improve-unexpected-fields-warning branch March 23, 2026 13:28
@github-project-automation github-project-automation bot moved this from In Review to Done in workers-sdk Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants