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

Remove DbActionExecutionException #1956

Closed
wants to merge 1 commit into from

Conversation

mipo256
Copy link
Contributor

@mipo256 mipo256 commented Dec 11, 2024

Targeting #831 issue

CC: @schauder @mp911de

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 11, 2024
@@ -110,12 +114,12 @@ private void execute(DbAction<?> action, JdbcAggregateChangeExecutionContext exe
} else {
throw new RuntimeException("unexpected action");
}
} catch (Exception e) {
} catch (RuntimeException e) {
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me that we should revisit our exception handling. DbActionExecutionException doesn't seem particularly useful to the final application whereas it might be useful for our own internals.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mp911de Yeah... But this is not a part of this issue. Maybe we can create another issue to revise the default exception to be thrown? Or what should we do?

Copy link
Member

Choose a reason for hiding this comment

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

The problem is that we're throwing DbActionExecutionException and not a DAO exception, so I think that is indeed part of the issue. Looking at the code, we do not catch DbActionExecutionException. That exception was introduced as part of introducing better means for debugging (#382) while the net effect was that we changed the API experience. What we could do is add DbActionExecutionException as suppressed exception to the original one.

Paging @schauder.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what you mean by "adding as suppresed exception".

In my understanding Surpressed exceptions are ones that get lost when a finalizer throws an exception itself.

We could instantiate a new exception with the same type as the original with the additional information of the DAEE, or even the DAEE as cause. That would certainly look strange, but might actually be rather useful.

Copy link
Member

Choose a reason for hiding this comment

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

Something along the lines of:

catch(RuntimeException e) {
  e.addSuppressed(new DbActionExecutionException(action));
  throw e;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm a little bit confused with adding suppressed exception here. We're not really suppressing DbActionExecutionException here. I see it confusing to the end user TBH.

CC: @mp911de @schauder

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know addSuppressed. It is a little hackish, but seems fine to me. It's not worse then the other variants I had in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@mipo256 mipo256 requested review from mp911de and schauder December 11, 2024 11:09
@mipo256 mipo256 force-pushed the GH-611 branch 2 times, most recently from ba1f4f0 to a8fbd8f Compare December 12, 2024 15:21
@mipo256
Copy link
Contributor Author

mipo256 commented Dec 13, 2024

Hey @schauder @mp911de!

I've done some polishing after code review, resolved both issues, can you take a look again?

@schauder
Copy link
Contributor

I'm still not happy with this.

  1. The JdbcExceptionTranslator is still hard wired (and has a rather non descriptive name).
  2. Part of the job is done in by the JdbcExceptionTranslator, and another part is done in the catch block. Without a clear reason why this is done this way.

I see two possible ways forward:
a) drop the exception handler and simply add the DbActionExecutionException as a suppressed exception to the catched exception. I'd consider this a breaking change, so this should go into 4.0

b) Implement a ExceptionTranslator, that unwraps any DbActionExecutionException, puts the original DbActionExecutionException as the suppressed exception on the original exception.
We could offer this exception translator to users in the next release, and in 4.0 register it by default.
The catch block would stay unchanged.

@mp911de What do you think?

@mp911de
Copy link
Member

mp911de commented Dec 16, 2024

I would honestly drop DbActionExecutionException entirely. We do not define it in our API (JdbcAggregateOperations doesn't define such a contract) so users do not expect that exception. I would even argue the sooner we remove DbActionExecutionException, the better. Our MyBatis integration doesn't care about DbActionExecutionException, it throws PersistenceException instead.

Going forward, I would even suggest introducing SQLExceptionTranslator to MyBatisDataAccessStrategy and refining the API contract at JdbcAggregateOperations to call out our delegations to NamedParameterJdbcOperations so users have an idea about exception usage.

@schauder
Copy link
Contributor

Just to clarify what wasn't clear to me from Marks statement:

For this PR we want to completely drop the ExceptionTranslator and the DbActionExecutionException and just utilise the ExceptionTranslater used by the JdbcTemplate.

The MyBatis integration should eventually also get its SqlExceptionTranslater. This can happen in this PR, or we would create a separate issue for that.

@mipo256
Copy link
Contributor Author

mipo256 commented Dec 16, 2024

I can do what @schauder summarized in this PR. We just need to conclude that we agree on the solution. What are your thoughts on this @mp911de?

@schauder
Copy link
Contributor

What I wrote above, was the result of a discussion with Mark, so please go ahead.

@mipo256
Copy link
Contributor Author

mipo256 commented Mar 13, 2025

Understood @schauder. Will complete shortly

@mipo256 mipo256 force-pushed the GH-611 branch 3 times, most recently from 6532a21 to 13673aa Compare March 13, 2025 19:11
@mipo256
Copy link
Contributor Author

mipo256 commented Mar 13, 2025

Done @schauder @mp911de

Because we're removing the DbActionExecutionException, I think we need to assign the breaking-change tag in order to merge the changes only into 4 major release.

Or maybe we can do better - we can just deprecate the DbActionExecutionException and keep it for now, but mark it as forRemoval = true. So the users will have a grace migration period. What are your thoughts, guys?

@schauder
Copy link
Contributor

It's not just about the existence of DbActionExecutionException, but also about exception handling that relies on the current structure, so I don't think there is a reasonable way around calling it a breaking change.

@schauder schauder added type: enhancement A general enhancement has: breaking-change An issue that is associated with a breaking change. and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 14, 2025
@mipo256
Copy link
Contributor Author

mipo256 commented Mar 14, 2025

I agree with you @schauder. I'm just pointing out that retaining the DbActionExecutionException may be "less breaking" for some users. But in general you're right.

Maybe just removing it entirely and not retaining the legacy in the next major version is a good way to go. Thanks!

@schauder
Copy link
Contributor

I see your idea, but if someone is referencing DbActionExecutionException anywhere in their code, it is actually useful to have that fail hard, because even if it would compile, it most certainly wouldn't work anymore as intended.

@schauder
Copy link
Contributor

This PR has test failures in JdbcRepositoryConcurrencyIntegrationTests.
Please fix those.

@schauder schauder changed the title GH-611 added JdbcExceptionTranslator Remove DbActionExecutionException Mar 14, 2025
@mipo256
Copy link
Contributor Author

mipo256 commented Mar 15, 2025

Fixed the concurrency tests in JdbcRepositoryConcurrencyIntegrationTests @schauder, the PR is ready.

schauder pushed a commit that referenced this pull request Mar 17, 2025
We now raise the exceptions from `NamedParameterJdbcTemplate` directly.

If you used to extract the `cause` of a `DbActionExecutionException` you should now catch that Exception directly.

Original pull request #1956
Closes #831

Signed-off-by: mipo256 <[email protected]>
schauder added a commit that referenced this pull request Mar 17, 2025
Formatting.
Fixing SQL scripts.

Original pull request #1956
See #831
schauder pushed a commit that referenced this pull request Mar 17, 2025
We now raise the exceptions from `NamedParameterJdbcTemplate` directly.

If you used to extract the `cause` of a `DbActionExecutionException` you should now catch that Exception directly.

Original pull request #1956
Closes #831

Signed-off-by: mipo256 <[email protected]>
schauder added a commit that referenced this pull request Mar 17, 2025
Formatting.
Fixing SQL scripts.

Original pull request #1956
See #831
@schauder
Copy link
Contributor

Thanks for pushing this forward.

I applied some polishing and some fixes to SQL scripts and merged it into 4.0.x

@schauder schauder closed this Mar 17, 2025
@schauder schauder added this to the 4.0 M2 (2025.1.0) milestone Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: breaking-change An issue that is associated with a breaking change. type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants