-
-
Notifications
You must be signed in to change notification settings - Fork 160
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
Chore: Improve arg/option error messages #162
Chore: Improve arg/option error messages #162
Conversation
In general I am in favor of a change like this. That said, I think because we are not using |
@wesleytodd Just to clarify, what exactly do you mean by "adding |
Ah sorry I was not clear, it is common practice to use So the idea is to first give users a better thing to do things like |
@wesleytodd Apologies, I'm unfamiliar with these practices currently (for now) so I'm getting the gist but not 100% certain exactly what sort of change you would like me to do (be that in this PR or in a separate PR); hence I was under the impression that simply changing the error message would be sufficient. If you could provide an example of the change I should make that would not be breaking in this instance, I would really appreciate that. (had I known that changing the error message itself would be considered a breaking change, I probably would've opened an issue first 😅) For clarity, my current understanding is that currently the errors are thrown only with messages. Therefore, current users of this library may potentially be handling errors by checking against the error's If that's the case, then I'd just need to know the preferred way you'd like me to implement this, whether I simply do something like // change this
default:
throw new TypeError('option sameSite is invalid');
// to this
default:
var sameSiteError = new TypeError('option sameSite is invalid');
sameSiteError.code = 'ERR_INVALID_ARG_VALUE';
throw sameSiteError; Or if it'd be preferable to create custom error objects with the appropriate codes and throw those as required. |
Your example is spot on! I dont think these simple errors need custom classes or anything, just what you showed would be perfect imo.
Basically the idea is that we only have one interface for users to check which type of error was thrown, the This is a GREAT direction though and I would love to see it land for the next major if we can. And to do that, landing |
Thank you for the confirmation and insight! TIL I'll get a fresh PR with a |
To be a bit more general for future contributions, the guideline I think about is "did I have to change the existing tests for this?" If yes, then I strongly consider if it could be breaking to users in the same way. |
That's a very good point I've not previously considered (haven't really worked on libraries much, especially something as fundamentally used as this). |
I think it would be best to test both in the new PR, then we can change this one to drop the |
Excellent - appreciate the guidance on this. |
Thanks for the PR @MaoShizhong, I'm going to land this now as it looks useful for a 1.0 release. I am going to make the error message formats consistent though, so revert to the old text and append the invalid option (it's harder to read/parse if the beginning always changes). |
@blakeembrey No problem, appreciated! Let me know if there's anything else needed from me, be that for this PR or the other one. |
Adding code is definitely useful but it can be added later as a backward compatible change, so I'm going to wait until we align on whether we want that for all the packages. Cheers! |
The current error messages for invalid option values (e.g. passing
sameSite: 2342
ormaxAge: 'cookie'
) are not sufficiently descriptive.Currently, those two examples will throw
option sameSite is invalid
andoption maxAge is invalid
respectively, both of which can be interpreted assameSite
ormaxAge
not being valid properties on the options object.Instead, the error messages would benefit from showing the provided value and stating that value is not a valid value for the respective option. That way, it's clear that the property is valid, just the provided value that's invalid, which is what actually is the case.
This PR