-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Enhancement: Better error message when a reserved keyword argument is incorrectly used. #2765
Comments
The issue with your proposal is that we don't have enough information to display such an error message. The message you proposed assumes some intent, namely that what the user wanted was to create a query parameter. Because we can't know what the intent was, the error message has to be generic. An error message saying you're doing something wrong that you're not even trying to do is even more confusing than an error message that's a bit generic. |
@provinzkraut fair. Can we still include a link to the relevant docs, please? This will point the user in the right direction, irrespective of their intent |
I'm not entirely against this, but since we're currently not doing this anywhere else, I think we should have a general discussion about this first. Adding those links will also add some maintenance burden, as we'll have to ensure they're all valid (some pages might move), update with the version, and stay semantically correct as the docs change. Nothing is more frustrating than a dead of nonsensical link. I also think that if we were to do this, we shouldn't do it just in this case, but more broadly. We could for example opt to employ a system like SQLAlchemy has, where all of these exception classes have their own error code, for which an explanation in the docs exists, linking to further reading material. |
@AgarwalPragy I have created #2768 to further discuss this issue. |
Summary
Litestar defines the following "reserved" keyword arguments for route handlers
https://docs.litestar.dev/2/usage/routing/handlers.html#reserved-keyword-arguments
It is possible for someone to use these names for their route parameters, without realizing that these are reserved names.
In this case, the error messages can be cryptic.
Basic Example
This gives the following error
The current error message does mention that
state
is areserved kwarg
, but that gets lost in the rest of the message.IMO, the message should read something like
Drawbacks and Impact
No response
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh Litestar dashboard
The text was updated successfully, but these errors were encountered: