[wrangler] Add upgrade hint to unexpected configuration field warnings#11800
[wrangler] Add upgrade hint to unexpected configuration field warnings#11800southpolesteve wants to merge 8 commits intomainfrom
Conversation
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.
🦋 Changeset detectedLatest commit: a8ceb52 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 finished @southpolesteve's task —— View job Changeset Review✅ All changesets look good The changeset
The changeset follows all guidelines from |
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: |
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.
vicb
left a comment
There was a problem hiding this comment.
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?
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. |
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.
904e5cf to
92cc8f4
Compare
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. |
|
Looking at the diffs: This PR is only adding noise here |
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.
petebacondarwin
left a comment
There was a problem hiding this comment.
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?"
| logger.warn(diagnostics.renderWarnings()); | ||
|
|
||
| // If there are unexpected field warnings and an update is available, suggest upgrading | ||
| if (diagnostics.renderWarnings().includes("Unexpected fields found")) { |
There was a problem hiding this comment.
This is a fragile check, what if we tweak the message?
I think it would be better to change the config validation so that it returns a flag or something when an unexpected field is found. Then check that instead.
There was a problem hiding this comment.
I think it would be better to change the config validation so that it returns a flag or something when an unexpected field is found. Then check that instead.
As discussed here and on offline channels, I think the long term fix is to use the schema and drop the hand written validation code so that we have a single exhaustive source of truth.
| const latestVersion = await updateCheck(); | ||
| if (latestVersion !== undefined) { | ||
| logger.log( | ||
| `If this is a new configuration option, consider updating Wrangler. ` + |
There was a problem hiding this comment.
What does "new" mean? If they are on a really old version of Wrangler then the option might not be new in any reasonable sense.
Instead I would propose that we say something more like:
"There is a newer version of Wrangler available. Try upgrading as this might support the unexpected option."
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:
Estimated effort: ~2-3 hours |
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.
Before:
After: