Skip to content

Conversation

@velo
Copy link
Member

@velo velo commented Feb 20, 2020

Inspired by #1173

I decided to add some extra information to contract parsing... to be attached to exceptions.

So, instead of just saying Method has too many Body parameters go figure what that means

I attached some extra bits:

java.lang.IllegalStateException: Method has too many Body parameters: public abstract feign.Response feign.DefaultContractTest$MixedAnnotations.findAllClientsByUid2(java.lang.String,java.lang.Integer,java.lang.Integer)
Warnings:
- Class MixedAnnotations has no annotations, it may affect contract Default
- Parameter String has annotations [Category] that are not used by contract Default
- Parameter Integer has no annotations, it may affect contract Default
	at feign.Util.checkState(Util.java:129)
	at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:124)
	at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:62)
	at feign.DeclarativeContract.parseAndValidateMetadata(DeclarativeContract.java:38)
...

probably needs more work =)
and introduces more mutability to MethodMetadata =(((

@velo velo requested a review from kdavisk6 February 20, 2020 09:02
Copy link
Member

@kdavisk6 kdavisk6 left a comment

Choose a reason for hiding this comment

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

I really like the idea that we track those warnings and potentially expose those to users. My comments are focused on the readability and clarifying the intention of the process.

.forEach(processor -> processor.process(annotation, data)));
if (Arrays.stream(targetType.getAnnotations())
.anyMatch(annotation -> classAnnotationProcessors.stream()
.anyMatch(processor -> processor.test(annotation)))) {
Copy link
Member

Choose a reason for hiding this comment

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

We may want to move this test into a function so we can call like getApplicableAnnotationProcessors() to make the intention clearer and make this more readable.

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't make this happen in a meaningful way.

There are 2 loops, so can't really get a single list that I can just use w/o further filtering.

Copy link
Member

Choose a reason for hiding this comment

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

Not asking you to simplify the loop, just move it to a function so it is a little more readable.

Arrays.stream(targetType.getAnnotations())
.forEach(annotation -> classAnnotationProcessors.stream()
.filter(processor -> processor.test(annotation))
.forEach(processor -> processor.process(annotation, data)));
Copy link
Member

Choose a reason for hiding this comment

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

Keying off my previous comment, the end result here is

Collection<AnnotationProcessor> applicableProcessors = this.getAnnotationProcessorsFor(targetType);
applicableProcessors.forEach(processor -> process(annotation, data));

.filter(processor -> processor.test(annotation))
.forEach(processor -> processor.process(annotation, data));
if (methodAnnotationProcessors.stream()
.anyMatch(processor -> processor.test(annotation))) {
Copy link
Member

Choose a reason for hiding this comment

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

Similar approach here, maybe create a function to do this test.

@kdavisk6 kdavisk6 added bug Unexpected or incorrect behavior chore For issues related to technical debt and other non-functional tasks and removed bug Unexpected or incorrect behavior labels Feb 27, 2020
@velo velo merged commit a9e631a into master Mar 9, 2020
@velo velo deleted the contract-breadcrumbing branch March 9, 2020 09:07
velo added a commit that referenced this pull request Oct 7, 2024
* Add extra information when failing to parse contract

* Add warnings to other error messages

* Move check if processor are valid before if block
velo added a commit that referenced this pull request Oct 8, 2024
* Add extra information when failing to parse contract

* Add warnings to other error messages

* Move check if processor are valid before if block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore For issues related to technical debt and other non-functional tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants