Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dario-piotrowicz
Copy link
Member

@dario-piotrowicz dario-piotrowicz commented Dec 15, 2025

Fixes #7755

Note

Implemented by Claude Opus 4.5 🤖

Detect TOML Date values in vars configuration early and provide a helpful error message explaining that unquoted dates like DATE = 2024-01-01 are parsed as Date objects, and how to fix it by wrapping in quotes.


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

@changeset-bot
Copy link

changeset-bot bot commented Dec 15, 2025

🦋 Changeset detected

Latest commit: 64f9f77

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

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Dec 15, 2025
@dario-piotrowicz dario-piotrowicz marked this pull request as ready for review December 15, 2025 17:19
@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner December 15, 2025 17:19
@dario-piotrowicz
Copy link
Member Author

The changes in this PR have been authored by Claude, I've manually tested them and they do seem to do the trick:
Screenshot 2025-12-15 at 17 20 20

@ascorbic
Copy link
Contributor

Could we instead make it behave correctly? i.e. convert it back to a string when parsing?

@dario-piotrowicz
Copy link
Member Author

Could we instead make it behave correctly? i.e. convert it back to a string when parsing?

good point 👍

@github-actions
Copy link
Contributor

Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the v3-maintenance branch with your changes. Thank you for helping us keep Wrangler v3 supported!

Depending on your changes, running git rebase --onto v3-maintenance main claude/7755 might be a good starting point.

Notes:

  • your PR branch should be named v3-backport-11651
  • add the skip-v3-pr label to the current PR to stop this workflow from failing

@dario-piotrowicz dario-piotrowicz changed the title fix: improve error message for Date values in wrangler.toml vars Automatically convert TOML Date values in vars to strings Dec 15, 2025
for (const [varName, varValue] of Object.entries(value)) {
if (varValue instanceof Date) {
// Convert Date to ISO date string (YYYY-MM-DD format)
const dateString = varValue.toISOString().split("T")[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct to convert to "YYYY-MM-DD" ?

TOML supports multiple distinct date formats and we might end up with a string that is not what is in the TOML file.

At least we should have more tests and test the round trip transformation from the string in TOML to the string value of the var

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The initial implementation is probably the right thing to do - there does not seem to be a way to get a original string value with the parsing lib we use

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure the real implementation creates smol-toml TomlDate objects which are Date subclasses. They can round-trip the string values. The problem is that the test is using JS Date objects. Really they should use parseToml to get the correct objects.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even then const dateString = varValue.toISOString().split("T")[0]; might work by chance or be broken.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with @vicb here, I've been poking around and the raw data seems to indeed get lost.

And as Victor pointed out there doesn't seem to be a reliable way to covert back the date to a string that resembles the user's text, so I do think that just erroring is the right implementation here 🤔

Copy link
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 think this will work with i.e. lt1 = 07:32:00

@github-project-automation github-project-automation bot moved this from Untriaged to In Review in workers-sdk Dec 16, 2025
TOML parses unquoted date values like DATE = 2024-01-01 as Date objects.
Previously this caused a confusing error from Miniflare. Now wrangler
automatically converts Date values to ISO date strings (YYYY-MM-DD format)
and shows a warning suggesting to wrap the value in quotes.

Co-authored-by: Dario Piotrowicz <[email protected]>
@dario-piotrowicz
Copy link
Member Author

I don't think this will work with i.e. lt1 = 07:32:00

indeed that would not work at all, I do think that we should just error 👍

@claude
Copy link
Contributor

claude bot commented Dec 18, 2025

Claude finished @dario-piotrowicz's task —— View job


Changeset Review

  • Read changeset guidelines
  • Review .changeset/floppy-tips-play.md
  • Review .changeset/tangy-knives-allow.md
  • Check for cute animals
  • Provide final assessment

All changesets look good

Both changeset files pass validation:

.changeset/floppy-tips-play.md (wrangler)

  • ✅ Version type: patch (correct for a bug fix improvement)
  • ✅ Clear title and helpful description with example
  • ✅ No h1/h2/h3 headers

.changeset/tangy-knives-allow.md (@cloudflare/workers-utils)

  • ✅ Version type: patch (correct for a bug fix improvement)
  • ✅ Clear title and helpful description with example
  • ✅ No h1/h2/h3 headers

Both changesets properly describe the symptom being fixed (unhelpful error messages for TOML date values) and provide clear examples of the correct usage. The change is correctly categorized as a patch-level improvement across both affected packages.


Cute Animal Report: No cute animals detected in the PR images. Only terminal screenshots and debug console output. 0/10 needs more animals.

@dario-piotrowicz dario-piotrowicz changed the title Automatically convert TOML Date values in vars to strings Error gracefully when encountering date values in TOML config files Dec 18, 2025
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 18, 2025

create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 64f9f77

if (varValue instanceof Date) {
diagnostics.errors.push(
`The field "${fieldPath}.${varName}" is a TOML date, which is not supported. ` +
`Please use a string instead, e.g. ${varName} = "${varValue.toISOString().split("T")[0]}".`
Copy link
Contributor

Choose a reason for hiding this comment

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

${varName} = "${varValue.toISOString().split("T")[0]}

is not really helpful for times. Maybe only ask to quote the value?

Copy link
Member Author

Choose a reason for hiding this comment

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

The value here is the TOML date object... so either way if a time is provided this is not going to be super useful... 😕 maybe an hardcoded example could do?

Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a TomlDate though, won't it? The toISOString method is different

Copy link
Member Author

Choose a reason for hiding this comment

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

oh.... you're right! 😓

And I've debugged this.... it can get pretty messy 😕

Screenshot 2025-12-19 at 16 24 10

So indeed I would just put a hardcoded example 🤔

Copy link
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.

LGTM, thanks!

(A few nit comments)

@github-project-automation github-project-automation bot moved this from In Review to Approved in workers-sdk Dec 19, 2025
@petebacondarwin petebacondarwin merged commit d123ad0 into main Dec 23, 2025
45 of 47 checks passed
@petebacondarwin petebacondarwin deleted the claude/7755 branch December 23, 2025 12:22
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Dec 23, 2025
AmirSa12 pushed a commit to AmirSa12/workers-sdk that referenced this pull request Jan 5, 2026
…loudflare#11651)

* fix: automatically convert TOML Date values in vars to strings

TOML parses unquoted date values like DATE = 2024-01-01 as Date objects.
Previously this caused a confusing error from Miniflare. Now wrangler
automatically converts Date values to ISO date strings (YYYY-MM-DD format)
and shows a warning suggesting to wrap the value in quotes.

Co-authored-by: Dario Piotrowicz <[email protected]>

* error insted of trying to convert to string

* Apply suggestions from code review

Co-authored-by: Victor Berchet <[email protected]>

* Apply suggestions from code review

Co-authored-by: Victor Berchet <[email protected]>

* Apply suggestions from code review

* use hardcoded example

* create toml dates using smol-toml in tests

---------

Co-authored-by: OpenCode Claude <[email protected]>
Co-authored-by: Victor Berchet <[email protected]>
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.

🐛 BUG: Better handling of dates in wrangler.toml environment variables

4 participants