-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ComponentReflection::combineArgs() throws InvalidArgumentException in…
…stead BadRequestException when incompatible type is object
- Loading branch information
Showing
3 changed files
with
10 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212ec43
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.
hi, what is the reason? Now app will show 500 instead of 404 page
212ec43
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.
It's also a BC break.
212ec43
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.
When an incompatible object is passed to presenter, it seems like logic exception, ie 500, not like 404. Or am I wrong?
212ec43
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.
Depends on how you define responsibility of router. Now you're forcing users to increase complexity of router to analyze target presenter via reflection.
212ec43
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.
Can you give me example?
212ec43
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.
Oh shit, this is still a problem and now we have it in production.
The example is rather obvious. You have a presenter with a class typehint (e.g.
Article $article
) and you have a general-purposeEntityFilteringRouter
(wrapper around anotherIRouter
) which converts parameterarticle
from integer (article id) to an instance ofArticle
without analyzing the target presenter signature via reflection.IMHO for the same reason the routers are currently not responsible to ensure that parameter
article
is an integer when presenter hasint $article
, the should not be responsible to ensure that parameterarticle
is a correct instance, i.e. I don't understand whyint
andArticle
typehint should be treated any differently.212ec43
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.
Because 4xx errors are usually not logged (ie not logged as logic errors), this commit helps you to discover logic error in code. 👍
212ec43
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.
@dg But this is where we disagree. I don't think this is a logic error. Please read the comment once again. I don't understand why int and Article typehint should be treated any differently.
212ec43
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.
Because user can fake URL to generate scalar or array parameter, but is unable to fake object.
212ec43
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.
Object can create only your router, so it is your logic bug.
212ec43
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.
No, logic bug = the router failed to fulfill his responsibility. But why should router be responsible for verifying type of parameters with class typehints and not for verifying type of parameters with scalar typehints?
If you change ComponentReflection to always throw InvalidArgumentException, it would be very odd, but consistent. It would mean that you have decided to move responsibility of parameter checking from presenter to router. But what you have done is in my view very inconsistent responsibility split. Router used to be more are less independent of presenters. You have suddenly broken this ancient agreement.
212ec43
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.
Simply: I remember that I commited this fix when I found out that the previous behavior conceal very serious bug in my code. If we are moving towards more strict language and code, it is logical to eliminate things that can silently conceal serious errors.
212ec43
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.
@dg But this is not about being more or less strict. This is about breaking IRouter API that has been stable for years in a way that introduces inconsistency to Nette overall design.
How about the following compromise (I'm not even sure myself whether it would be actually a good idea). Throw InvalidArgumentException when instance of different class / wrong type is given, throw BadRequestException when the argument is simply missing.
212ec43
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.
#173