Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Better exception messages for the Service Container. #1922

Open
frankdejonge opened this issue Mar 18, 2018 · 6 comments
Open

Better exception messages for the Service Container. #1922

frankdejonge opened this issue Mar 18, 2018 · 6 comments

Comments

@frankdejonge
Copy link

The issue

When the container is not able to construct one of its dependencies you don't know which class it was trying to resolve initially. This makes it very hard figure out which dependency was being resolved in the first place.

Possible solution

If exceptions are caught and re-thrown when a dependency is resolved a dependency chain could be built up. This would be used in the final message to give a better hint why a dependency cannot be resolved.

@tillkruss
Copy link

Could you post a link to where the exception is thrown?

@frankdejonge
Copy link
Author

@tillkruss I don't know what you mean.

@tillkruss
Copy link

@frankdejonge: I mean what's the exception that's thrown if a dependency can't be resolved. I wanted to check it out how easy it is to fix this.

@driesvints
Copy link
Member

Actually, this should be shown in the exception message. The container keeps a build stack and adds the previous resolved classes from the chain to the exception message as you can see here:

https://github.com/laravel/framework/blob/0973092309548463424c21f862abf1de64d57153/src/Illuminate/Container/Container.php#L937-L941

Is this not working for you? Can you provide some code in order to let us recreate it?

@frankdejonge
Copy link
Author

@driesvints if I remember correctly it's when dependency is resolved that depends on something that's not instantiable. The error message could be try/catch'ed around the call that resolved the dependencies and retrown with the service identifier (or classname) that was the root of the dependency tree.

@driesvints driesvints transferred this issue from laravel/framework Nov 14, 2019
@driesvints
Copy link
Member

Transferred this issue to the ideas repository instead.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants