-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Ambiguous error when parsing some of falsy values #16
Comments
I opened PR on (Sorry if this is a weird question, by the way. I am new to open source contribution.) |
Maintainers are often busy with lots of repos and can't always prioritize reviewing PRs. Give it some time. To maximize your chances of getting it merged, try to make the minimal amount of changes to fix the problem, and don't forget to add tests ;) I would for example, throw early, so you don't have to wrap the whole existing code in an else statement: if (typeof txt !== 'string') {
const type = typeof txt === 'undefined' ? ' ' : ` the ${typeof txt} `
e.message = `Cannot parse${type}${String(txt)}`
throw e;
} I'm also not sure why you're special-casing |
Thanks for the advice As for special-casing |
I don't see the point in mentioning that
|
Actually, why even do the check after parsing. We know up front those types are not valid, so you can just throw a |
I agree that The reason I put the check after parsing is to preserve performance for valid strings. Would it be still better to always check the type before parsing? |
I would rather just special-case this one, with:
That's a good point. Yeah, makes more sense to optimize for the common-case. |
Yeah the special-case message looks good. Thank you so much for the help. |
@sindresorhus The fix is now merged to |
Great! Thanks for working on it :) |
When I parsed
undefined
, the error wasFor
NaN
It would be more friendly error if it just says something like
don't give me undefined/NaN!
(in more formal way, of course)I don't know if this has mentioned before, but at least I could not find related issues.
The text was updated successfully, but these errors were encountered: