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

Config processing with lazy error handling #127

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

luk-kaminski
Copy link

@luk-kaminski luk-kaminski commented Mar 27, 2024

Fixes #126

Notes for Reviewers

  • The commit history must be preserved - please use the rebase-merge or standard merge option instead of squash-merge
  • Sync up with the author before merging

@todvora
Copy link
Contributor

todvora commented Apr 19, 2024

I have adapted the behaviour to match the eager processing mode. The lazy method now doesn't return any result, the return type is void. The outcome of the processing is either configured beans or a ValidationException, aggregating all the errors and providing access to the underlying ProcessingResponse, if the caller wants to handle the errors in a specific way.

This is how the exception looks now, aggregating three missing properties:

image

The only change from the caller perspective is to switch from jadConfig.process() to jadConfig.processFailingLazily(). Everything else can stay as it is, with the same error handling in place as before.

image

Comment on lines 22 to 23
import static com.github.joschi.jadconfig.ReflectionUtils.getAllFields;
import static com.github.joschi.jadconfig.ReflectionUtils.getAllMethods;
import static com.github.joschi.jadconfig.ReflectionUtils.invokeMethodsWithAnnotation;
import static com.github.joschi.jadconfig.ReflectionUtils.*;
Copy link
Member

Choose a reason for hiding this comment

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

Please remove the wildcard import.

}

ProcessingResponse doProcessFailingLazily() throws RepositoryException {
ProcessingResponse response = new ProcessingResponse();
Copy link
Member

Choose a reason for hiding this comment

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

The response can be final.

Copy link
Contributor

Choose a reason for hiding this comment

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

rewritten this block to avoid all mutations of the ProcessingResponse.

if (parameter != null) {
LOG.debug("Processing field {}", parameter);
private Map<String, Exception> processClassFieldsFailingLazily(Object configurationBean, Field[] fields) {
Map<String, Exception> fieldProcessingProblems = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

The field can be final.

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

@@ -242,6 +293,27 @@ private void invokeValidatorMethods(Object configurationBean, Method[] methods)
}
}

private Map<String, Exception> invokeValidatorMethodsFailingLazily(Object configurationBean, Method[] methods) {
Map<String, Exception> problems = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

The field can be final.

Copy link
Contributor

Choose a reason for hiding this comment

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

fixed

Comment on lines -57 to +56
public void validate() throws ValidationException {
public void myCustomValidatorMethod() throws ValidationException {
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for renaming this method?

Copy link
Contributor

Choose a reason for hiding this comment

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

The name of the method is string-matched later in the test. "validate" seems like too vague name and it's not really clear where it is coming from. Changing the name to "myCustomValidatorMethod" makes the connection clear and and removes any doubts.

Comment on lines 31 to 32
// TODO: should we distinct between field processing problem and validation method?
// TODO: should we include class name of the bean or not?
Copy link
Member

Choose a reason for hiding this comment

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

Are these still open tasks?

Copy link
Contributor

Choose a reason for hiding this comment

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

no, removed the todo and simplified the code

@todvora todvora requested a review from bernd June 6, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Collect all validation errors and then fail
3 participants