Skip to content

Conversation

@MalikinSergey
Copy link
Contributor

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()

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()
@GrahamCampbell
Copy link
Collaborator

Fix the cs.

@MalikinSergey
Copy link
Contributor Author

Done, right?

Copy link
Collaborator

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.

@GrahamCampbell
Copy link
Collaborator

Thanks. Please fix the remaining issue, add tests, and squash to one commit.

@GrahamCampbell
Copy link
Collaborator

Also, please send this to 5.1. It's a change in behaviour.

@MalikinSergey
Copy link
Contributor Author

@GrahamCampbell
about test, it's need to add to RoutingUrlGeneratorTest::testBasicRouteGeneration() case like this?

$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

@franzliedke
Copy link
Contributor

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.

@GrahamCampbell
Copy link
Collaborator

Not really. The misleading error message is the current behaviour people expect from 5.0. Throwing an exception instead would be a bc break.

@franzliedke
Copy link
Contributor

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.

@barryvdh
Copy link
Contributor

I've also encountered the Call to a member function domain() on a non-object error, it's pretty confusing indeed. The old behaviour didn't work right? So not sure how this is breaking?

@MalikinSergey
Copy link
Contributor Author

@franzliedke @barryvdh
I agree with @GrahamCampbell, it's a behaviour change; for example, somebody can write logic like

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

Minor features that are fully backwards compatible with the current Laravel release may be sent to the latest stable branch.

So, I've sent pull #7453 to 5.1 master branch

@MalikinSergey
Copy link
Contributor Author

But I recognize, that current behaviour with fatal exception is very complicated to debug

@franzliedke
Copy link
Contributor

@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.

@JoostK
Copy link
Contributor

JoostK commented Feb 16, 2015

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 Route::getRoutes()->getByAction($action);.

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.

@taylorotwell taylorotwell reopened this Feb 16, 2015
taylorotwell added a commit that referenced this pull request Feb 16, 2015
Add exception throwing, when controller action not found
@taylorotwell taylorotwell merged commit 48fee81 into laravel:5.0 Feb 16, 2015
@MalikinSergey MalikinSergey deleted the patch-1 branch February 16, 2015 19:01
@mikerogne
Copy link

Phew, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants