Skip to content
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

More human readable error messages #30

Closed
Ayc0 opened this issue Feb 22, 2024 · 3 comments
Closed

More human readable error messages #30

Ayc0 opened this issue Feb 22, 2024 · 3 comments

Comments

@Ayc0
Copy link

Ayc0 commented Feb 22, 2024

I don't really know if this is an issue that should be opened here, or on the RFC. In the rfc I just saw those generic TypeError:

image

So I think the error message is handled by the polyfill directly.

When creating an object from an invalid, for instance:

Temporal.Duration.from({ days: undefined });
// Throws:
// TypeError: No valid fields
//     at refineFields (index.cjs:1309:15)
//     at exports.refineDurationBag (index.cjs:2498:30)
//     at toDurationSlots (index.cjs:2857:89)
//     at Function.from (index.cjs:3316:37)
//     at Timeline.tsx:22:21

My use case: I used it with Temporal.Duration.from({ day: 5 }), and it didn't tell me that "day" wasn't valid and that I should use "days" instead. And also another time with Temporal.Duration.from(durationObject) but all fields were empty.

What if instead, if non-valid fields are passed, the polyfill could day something like "day" isn't a valid field. It needs to be either "years", "months", …. Or Duration is created from an empty object. At least 1 field as to be a number to be valid

This is low priority, but it can make debugging easier with the polyfill

@arshaw
Copy link
Member

arshaw commented Feb 27, 2024

Thanks @Ayc0. I agree that the error message should be clearer. It'd be easy to print out a helpful list of the valid options in the case. I'll get this done for the next release.

@arshaw
Copy link
Member

arshaw commented Mar 1, 2024

This has been fixed in v0.2.3

will say something like:

No valid fields: days,hours,microseconds,milliseconds,minutes,months,nanoseconds,seconds,weeks,years

@arshaw arshaw closed this as completed Mar 1, 2024
@Ayc0
Copy link
Author

Ayc0 commented Mar 1, 2024

Amazing 🤩
Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants