mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
flush() lacks annotations about throwing UniqueConstraintViolationException exception #6271
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Atulin on GitHub (Jul 24, 2019).
Bug Report
Summary
flush()(or something deeper) lacks annotations about throwingUniqueConstraintViolationExceptionexception, and yet it does throw it when an attempt at adding a duplicate entry is made.Current behavior
flush()does throw theUniqueConstraintViolationExceptionexception properly, but PHPStorm complains withHow to reproduce
Expected behavior
PHPStorm doesn't complain, I guess ¯\_(ツ)_/¯
@SenseException commented on GitHub (Jul 29, 2019):
Thank you for reporting this issue. As far as I understand your issue is less a bug and more a DX one with the entity manager and PHPStorm (and probably other IDEs too). Do you like to create a pull request to improve DX for that?
@Atulin commented on GitHub (Jul 29, 2019):
I'm not sure what "DX" means in this context. If you could tell me what can be done to fix the issue, I'll try to implement that fix and create a PR, if I'm able to.
@SenseException commented on GitHub (Aug 1, 2019):
DX is for Developer Experience.
I guess
UniqueConstraintViolationExceptionwasn't added as a phpdoc toflush()because it is an exception of DBAL and not ORM.@Ocramius Should an exception of another library be added as a
@throw?@Ocramius commented on GitHub (Aug 1, 2019):
No, I'd say that we should keep documented exceptions to what is clearly thrown by underlying interfaces. Implementations are still capable of throwing exceptions that aren't within the declared set, and those cannot be declared, since anything in the engine can also crash spectacularly (in this language)
@gbirke commented on GitHub (Feb 28, 2022):
Could you catch and re-throw the DBAL exceptions as an
ORMExceptioninstead (wrapping the UniqueConstraintViolationException in thepreviousparameter of the ORMException)? Then the declared exceptions won't need to change and the catching code could still inspect the ORMException (callinggetPrevious) to see what happened and recover in some cases.I've also run into this issue while using PHPStan and will propose a temporary workaround on the doctrine extension until we have a resolution here.