-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Add exception throwing, when controller action not found #7424
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
Conversation
If undefined action passed In UrlGenerator::action(), it's throw fatal exception `Call to a member function domain() on a non-object` with fully uninformative debug stack because route, which was returned by `$this->routes->getByAction($action)` is not checked, before it passes to `$this->toRoute(...` and can be `null` instead of `Route` So, it seems logical to add some check, as in UrlGenerator::route()
|
Fix the cs. |
|
Done, right? |
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.
Reverse the logic here, and throw the exception inside the guard statement.
|
Thanks. Please fix the remaining issue, add tests, and squash to one commit. |
|
Also, please send this to 5.1. It's a change in behaviour. |
|
@GrahamCampbell $nonExistsAction = 'SomeControllerThatNotExists@action';
$this->setExpectedException('InvalidArgumentException','"Action {$nonExistsAction} not defined."');
$url->action($nonExistsAction);https://github.com/laravel/framework/blob/5.0/tests/Routing/RoutingUrlGeneratorTest.php#L114 |
|
How's this a change in behaviour? There used to be a misleading error message, now we throw an exception? That makes sense, and it's a bug fix. |
|
Not really. The misleading error message is the current behaviour people expect from 5.0. Throwing an exception instead would be a bc break. |
|
I'm fairly sure people do not build on this behaviour. There used to be an exception, now there's another one. This is still totally valid. |
|
I've also encountered the |
|
@franzliedke @barryvdh try{
$action = action('non-exists-controller@bar');
}
catch(FatalException $fatal){
//some logic for handle this
}and if we will change exception type, this code will not work properly. See http://laravel.com/docs/4.2/contributions#which-branch
So, I've sent pull #7453 to 5.1 master branch |
|
But I recognize, that current behaviour with fatal exception is very complicated to debug |
|
@MalikinSergey Of course this is technically breaking. But I don't see who would build something around it like this... especially given that you shouldn't and you're simply dealing with a non-existant controller action. |
|
Relying on such a bug to potentially detect if a route exists is very much a dirty hack, to be solved very differently, e.g. by This is an implementation detail and should never have been relied upon. Using the arguments here we can label almost every bug-fix as backwards incompatible, as someone may always have written a dirty hack around it. |
Add exception throwing, when controller action not found
|
Phew, thanks :) |
If undefined action passed In UrlGenerator::action(), it's throw fatal exception
Call to a member function domain() on a non-objectwith fully uninformative debug stack
because route, which was returned by
$this->routes->getByAction($action)is not checked, before it passes to$this->toRoute(...and can benullinstead ofRouteSo, it seems logical to add some check, as in UrlGenerator::route()