Skip to content

Unwrap RetryableException and throw cause - #737

Merged
velo merged 9 commits into
OpenFeign:masterfrom
dinomite:proxy-throw-cause
Oct 22, 2018
Merged

velo merged 9 commits into
OpenFeign:masterfrom
dinomite:proxy-throw-cause

Conversation

@dinomite

@dinomite dinomite commented Jul 8, 2018 •

Copy link
Copy Markdown
Contributor

As described in #709, this changes Feign to unwrap RetryableExceptions to throw the underlying cause in the event retrying fails.

This will require documentation updates, but I wanted to make a PR to show the changes for discussion first.

@kdavisk6

Copy link
Copy Markdown
Member

@dinomite the builds is failing during some of the test cases. Can you please look at those and update the PR?

if (th instanceof RetryableException && cause != null) {
throw cause;
}
throw th;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels like we are breaking the previous signature for all feign methods and interfaces... before we would throw FeignException, now we throw Exception.

I think we could introduce a new method into the Retryer called propagateException(FeignException), and ship feign with 2 implementations.

  • Legacy throws the current FeignException
  • Cause throws the root cause for a FeignException

@kdavisk6 kdavisk6 Jul 10, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a breaking change, we should weigh that carefully.

Should we consider a mechanism similar to Hystrix Javanica?

    Object process(Action action) throws Exception {
        Object result;
        try {
            result = action.execute();
            flushCache();
        } catch (CommandActionExecutionException throwable) {
            Throwable cause = throwable.getCause();
            if (isIgnorable(cause)) {
                throw new HystrixBadRequestException(cause.getMessage(), cause);
            }
            if (cause instanceof RuntimeException) {
                throw (RuntimeException) cause;
            } else if (cause instanceof Exception) {
                throw (Exception) cause;
            } else {
                // instance of Throwable
                throw new CommandActionExecutionException(cause);
            }
        }
        return result;
    }

There is an assumption made that unless a particular option is set, the original exception is thrown. If the original exception cannot be thrown, it is wrapped and thrown. In Feign, we always wrap the exception. I think this is the core issue @dinomite and I have been discussing in #737. Maybe we can add a top level option or annotation to Target methods that allow for finer control over what exceptions get wrapped and what exceptions do not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dinomite what are your thoughts on our suggestions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for reminding me that I had forgotten about this.

You're definitely right that this is big change, so doing it in a backwards-compatible way is the most tenable—I'd be ok with either @velo's suggestion of a pluggable solution or what you have suggested, @kdavisk6. I'm a bit out of context on Feign recently, do either of these look better to you all? Should Does one of them sound preferable for me to give a go at?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We will leave that up to you to choose. The goal is to limit our exposure to existing clients.

I think we can expand on @velo's suggestion to add a new method to the Builder called propagateExceptions which will change the default Retryer registered. This will allow existing integrations to work and those that want the behavior to enable it without having to add additional code. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I liked it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it. I'll have some updates to this PR in the next week or two.

@kdavisk6 kdavisk6 added the enhancement For recommending new capabilities label Jul 16, 2018
@kdavisk6 kdavisk6 added the breaking change Change that proposes a non-backward compatible breaking change label Aug 10, 2018
@velo velo added the waiting for feedback Issues waiting for a response from either to the author or other maintainers label Sep 16, 2018
@dinomite

Copy link
Copy Markdown
Contributor Author

@kdavisk6 Sorry, traveling right now—I'll provide a proper reply next week.

velo and others added 3 commits September 24, 2018 09:47
Add configuration to Feign.Builder and support in SynchronousMethodHandler
to make it propagate the cause of RetryableExceptions
@dinomite

dinomite commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

Updated—I liked the suggestion of adding propagation configuration in the builder, thanks for getting me started. The change is in SynchronousMethodHandler, catching RetryableExceptions that continueOrPropagate() may throw and, if propagateExceptions is enabled and there is a cause, the cause is thrown instead of the RetryableException.

@dinomite

dinomite commented Oct 5, 2018

Copy link
Copy Markdown
Contributor Author

Updated the README

Comment thread README.md Resolved
private final ErrorDecoder errorDecoder;
private final boolean decode404;
private final boolean closeAfterDecode;
private final boolean propagateExceptions;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like the PR and the general idea....

The only think I would ask is to replace this boolean propagateExceptions with an enum ExceptionPropagationPolicy propagationPolicy

Loved the builder. propagateExceptions() idea

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good to me, updates soon.

@velo velo removed the breaking change Change that proposes a non-backward compatible breaking change label Oct 6, 2018
@velo

velo commented Oct 6, 2018

Copy link
Copy Markdown
Member

Nice, liked the new work, removed the breaking change label as now is a configuration

@kdavisk6 kdavisk6 added this to the 10.1.0 milestone Oct 10, 2018
@dinomite

Copy link
Copy Markdown
Contributor Author

@velo How does this look? c2233bb

@velo

velo commented Oct 11, 2018

Copy link
Copy Markdown
Member

Looks good, I will merge once build passes

@dinomite

Copy link
Copy Markdown
Contributor Author

Hmm, looking into that error…

@velo
velo merged commit 4b2a48e into OpenFeign:master Oct 22, 2018
@dinomite
dinomite deleted the proxy-throw-cause branch October 22, 2018 22:00
velo pushed a commit that referenced this pull request Oct 7, 2024
* Throw cause of RetryableExceptions

* Allow propogation of underlying exceptions

Add configuration to Feign.Builder and support in SynchronousMethodHandler
to make it propagate the cause of RetryableExceptions

* Retab SMH

* Add note about propagation in readme

* Use enum for exception propagation policy
velo pushed a commit that referenced this pull request Oct 8, 2024
* Throw cause of RetryableExceptions

* Allow propogation of underlying exceptions

Add configuration to Feign.Builder and support in SynchronousMethodHandler
to make it propagate the cause of RetryableExceptions

* Retab SMH

* Add note about propagation in readme

* Use enum for exception propagation policy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For recommending new capabilities waiting for feedback Issues waiting for a response from either to the author or other maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants