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

GH-611 added JdbcExceptionTranslator #1956

Open
wants to merge 1 commit into
base: main
Choose a base branch
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
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants