-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Error gracefully when encountering date values in TOML config files #11651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest 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 |
|
Could we instead make it behave correctly? i.e. convert it back to a string when parsing? |
good point 👍 |
08d182e to
2fbaed8
Compare
|
Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running Notes:
|
2fbaed8 to
3519de0
Compare
vars to strings
| 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]; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC https://github.com/squirrelchat/smol-toml/blob/mistress/test/date.test.ts#L39 show that it doesn't roundtrip unchanged
There was a problem hiding this comment.
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 🤔
vicb
left a comment
There was a problem hiding this 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
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]>
indeed that would not work at all, I do think that we should just error 👍 |
3519de0 to
d1875f8
Compare
|
Claude finished @dario-piotrowicz's task —— View job Changeset Review
✅ All changesets look good Both changeset files pass validation:
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. |
vars to stringsd1875f8 to
184d673
Compare
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: |
Co-authored-by: Victor Berchet <[email protected]>
Co-authored-by: Victor Berchet <[email protected]>
| 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]}".` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vicb
left a comment
There was a problem hiding this 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)
packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts
Outdated
Show resolved
Hide resolved
…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]>


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.
varsto strings #11652A picture of a cute animal (not mandatory, but encouraged)