Skip to content

Improve FailureAnalyzer for embedded datasource #11953

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

Closed
wants to merge 5 commits into from
Closed

Improve FailureAnalyzer for embedded datasource #11953

wants to merge 5 commits into from

Conversation

pkostrzewa
Copy link
Contributor

@pkostrzewa pkostrzewa commented Feb 7, 2018

Fixes gh-8029.

  • Moved and refactored logic related to failure analysis from exception to DataSourceBeanCreationFailureAnalyzer.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 7, 2018
@snicoll snicoll self-requested a review February 7, 2018 17:03
@@ -520,39 +520,39 @@ public void setProperties(Map<String, String> properties) {

}

static class DataSourceBeanCreationException extends BeanCreationException {
class DataSourceBeanCreationException extends BeanCreationException {
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 not sure whether I should remove static modifier. Maybe it would be even better to move this class outside of DataSourceProperties?

@pkostrzewa
Copy link
Contributor Author

@snicoll any feedback would be appreciated :)

Copy link
Member

@snicoll snicoll left a comment

Choose a reason for hiding this comment

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

Thanks for the PR but that change doesn't need to be that involved. The exception doesn't need to change but perhaps it can expose extra information.

The real deal is the failure analyzer. We need to reformat the description as described in the related issue.

}

private String createDescription(DataSourceBeanCreationException cause) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think that's what I had in mind. What we need to do here is check if "NONE" is active and change the description accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean that such detailed description should be provided only in case when connection stands for "NONE"?

Copy link
Member

Choose a reason for hiding this comment

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

No that's not what I meant. I think we need to take a step back. Can you rework your PR to change the exception to expose the EmbeddedDatabaseConnection? Then you can adapt the message when it is NONE. The change to fix that issue must not be that large. Let me know if that works for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's ok for me. Actually I've reworked it similarly .

}

}
public Environment getEnvironment() {
Copy link
Member

Choose a reason for hiding this comment

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

You can't expose such thing in an exception.

}
message.append(".");
return message.toString();
public EmbeddedDatabaseConnection getConnection() {
Copy link
Member

Choose a reason for hiding this comment

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

Idem

DataSourceBeanCreationException(EmbeddedDatabaseConnection connection,
Environment environment, String property) {
super(getMessage(connection, environment, property));

super("Cannot auto-configure DataSource. ");
Copy link
Member

Choose a reason for hiding this comment

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

If you want to pursue this, the message should be provided by the caller, you can't hard-code it like that.

@pkostrzewa
Copy link
Contributor Author

pkostrzewa commented Feb 9, 2018

There are two options:

Which one do you prefer @snicoll ?

@snicoll
Copy link
Member

snicoll commented Feb 9, 2018

@pkostrzewa Thanks. I think that we need to revert the logic and build the message in the failure analyzer as you've done initially. But I'd like the changes to be a bit more focused. Here is what you can do:

  • You can inject the Environment in a FailureAnalyzer if you implement EnvironmentAware (FailureAnalyzer should be able to inject the environment #11569)
  • We can expose the EmbeddedDatabaseConnection in the exception as a getter
  • We can simplify the message to use the "property" part. We can use that then in the failure analyzer as a support to build the description message, the two message can be "Failed to determine a suitable driver class" and "Failed to determine a suitable jdbc url". We can build those message as is in the caller rather than computing them in the exception

So our exception takes now a message (see above) and an EmbeddedDatabaseConnection. Once you have that, we can craft a better error message. And we can have a special case for NONE to indicate that no embedded database was found on the classpath.

@pkostrzewa
Copy link
Contributor Author

pkostrzewa commented Feb 9, 2018

  • EmbeddedDatabaseConnection exposed as a getter in exception
  • DataSourceBeanCreationFailureAnalyzer implements EnvironmentAware so that current environment can be accessed
  • DataSourceBeanCreationException takes an connection and a message
  • Available actions are computed based on whether the connection type is EmbeddedDatabaseConnection.NONE
  • DataSourceProperties class in no longer aware of Environment as it was only passed as an exception argument

Currently there are no tests that covers all edge cases - maybe we should take them into consideration?

@snicoll snicoll self-requested a review February 10, 2018 14:08
@snicoll snicoll self-assigned this Feb 10, 2018
@pkostrzewa
Copy link
Contributor Author

@snicoll any feedback?

@snicoll snicoll added type: enhancement A general enhancement priority: normal and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 12, 2018
@snicoll snicoll added this to the 2.0.0.RC2 milestone Feb 12, 2018
@snicoll snicoll changed the title Improve FailureAnalyzer for embedded datasource Fixes gh-8029 Improve FailureAnalyzer for embedded datasource Feb 12, 2018
snicoll pushed a commit that referenced this pull request Feb 12, 2018
@snicoll snicoll closed this in 2f13449 Feb 12, 2018
snicoll added a commit that referenced this pull request Feb 12, 2018
* pr/11953:
  Polish "Improve FailureAnalyzer for embedded datasource"
  Improve FailureAnalyzer for embedded datasource
@snicoll
Copy link
Member

snicoll commented Feb 12, 2018

@pkostrzewa this is better but not quite there yet. Given the back and forth, I've polished your last proposal, see 2f13449

@snicoll snicoll removed their request for review February 12, 2018 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants