Skip to content
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

Add our own DB exception abstraction #25091

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Jan 12, 2021

Right now our API exports the Doctrine/dbal exception. As we've seen
with the dbal 3 upgrade, the leakage of 3rdparty types is problematic as
a dependency update means lots of work in apps, due to the direct
dependency of what Nextcloud ships. This breaks this dependency so that
apps only need to depend on our public API. That API can then be vendor
(db lib) agnostic and we can work around future deprecations/removals in
dbal more easily.

Right now the type of exception thrown is transported as "reason". For
the more popular types of errors we can extend the new exception class
and allow apps to catch specific errors only. Right now they have to
catch-check-rethrow. This is not ideal, but better than the dependnecy
on dbal.

Follow-up to #24948

@ChristophWurst ChristophWurst added enhancement 3. to review Waiting for reviews technical debt pending documentation This pull request needs an associated documentation update labels Jan 12, 2021
@ChristophWurst ChristophWurst added this to the Nextcloud 21 milestone Jan 12, 2021
@ChristophWurst ChristophWurst self-assigned this Jan 12, 2021
Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good 👍

@@ -25,12 +25,15 @@

namespace OC\DB;

use Doctrine\DBAL\Exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something complains on the imports

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was one unused below

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 apart of the comment

@ChristophWurst ChristophWurst force-pushed the enhancement/ocp-db-exception-abstraction branch from b1e7305 to 6e2410f Compare January 12, 2021 13:16
@rullzer rullzer mentioned this pull request Jan 12, 2021
14 tasks
Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will hit like a truck 🙈

@ChristophWurst
Copy link
Member Author

This will hit like a truck see_no_evil

Oh yes. But to be fair not only because of this PR. It will already hit hard since the original doctrine exception vanished. So it's just a matter of which new exception to listen for. And some of the now thrown exceptions were thrown before too. They were just not documented in our abstraction, but very present in the Doctrine signature.

@nickvergessen
Copy link
Member

Well all the UniqueConstraintViolation and so on still exist and worked (until this PR) Only the catch all didn't

@ChristophWurst
Copy link
Member Author

Right. I hadn't factored that in. But then these special exceptions were never documented to be thrown … 😛

@MorrisJobke
Copy link
Member

Psalm says no

@ChristophWurst ChristophWurst force-pushed the enhancement/ocp-db-exception-abstraction branch from 6e2410f to 01afbba Compare January 12, 2021 15:29
@ChristophWurst
Copy link
Member Author

Psalm says no

Look again. It's unrelated.

Right now our API exports the Doctrine/dbal exception. As we've seen
with the dbal 3 upgrade, the leakage of 3rdparty types is problematic as
a dependency update means lots of work in apps, due to the direct
dependency of what Nextcloud ships. This breaks this dependency so that
apps only need to depend on our public API. That API can then be vendor
(db lib) agnostic and we can work around future deprecations/removals in
dbal more easily.

Right now the type of exception thrown is transported as "reason". For
the more popular types of errors we can extend the new exception class
and allow apps to catch specific errors only. Right now they have to
catch-check-rethrow. This is not ideal, but better than the dependnecy
on dbal.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst ChristophWurst force-pushed the enhancement/ocp-db-exception-abstraction branch from 01afbba to 2c9cdc1 Compare January 12, 2021 15:38
*
* @since 21.0.0
*/
public const REASON_CONSTRAINT_VIOLATION = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the plan is first to have this generic and then maybe at a later stage have constraint violation exceptions? Or just document it properly and have the callers check the reason?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and yes. The generic way is that the just catch this exception and optonally compare the reason to a constant. And later we can have specific subclasses that can be caught

@rullzer rullzer mentioned this pull request Jan 14, 2021
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants