-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
ObjectManager interface lacks of @throws
annotation.
#340
Comments
I'm afraid we won't be able to define a good contract for exceptions... and throwing a generic |
I'm not sure to understand the issue. Having something like
doesn't force you to throw generic exceptions. You can have
and so on. This could be useful to have indeed something like a |
Sorry for making my thoughts so brief, let me fix that :) I tried to take a look at interface vs what exceptions ODM/ORM throw and I believe there's not much shared exceptional-state. I'm discarding all
Rest are simple methods that do not throw exceptions. Which leaves us with:
|
MappingException could be thrown by any method if your mapping is invalid. And the ORM does not wrap exceptions coming from DBAL for instance (and I don't think it should as it could not wrap them in meaningful ways). |
Somewhat related: doctrine/orm#7786 |
When looking at the ObjectManager interface
https://github.com/doctrine/persistence/blob/3.2.x/src/Persistence/ObjectManager.php
there si none
@throws
annotation for each methods.When looking at the ORM implementation
https://github.com/doctrine/orm/blob/2.16.x/lib/Doctrine/ORM/EntityManager.php
or the ODM implementation
https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/DocumentManager.php
a lot of exception are thrown in those methods.
The interface contract should be about the
@param
,@return
but also@throws
.If I write
I have no help from PHPStorm or PHPStan that an exception can be thrown and that I should try/catch the call sometimes.
When I write
PHPStan analysis help me to handle correctly exceptions (see https://phpstan.org/blog/bring-your-exceptions-under-control).
What could be great would be to
Doctrine\Persistence\Exception
class or interface@throws Doctrine\Persistence\Exception
to methods which can throws exceptionThe text was updated successfully, but these errors were encountered: