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

Introduce assorted Reactor error handling Refaster rules #318

Merged
merged 2 commits into from
Oct 30, 2022

Conversation

Ptijohn
Copy link
Contributor

@Ptijohn Ptijohn commented Oct 27, 2022

No description provided.

@Ptijohn Ptijohn requested a review from rickie October 27, 2022 11:55
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Rebased and added a commit. Suggested commit message:

Introduce assorted Reactor error handling Refaster rules (#318)

static final class MonoOnErrorResume<T> {
@BeforeTemplate
Mono<T> before(Mono<T> mono, Class<? extends Throwable> clazz, Mono<T> other) {
return mono.onErrorResume(clazz::isInstance, e -> other);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of e -> other we should use Function<? super Throwable, ? extends Mono<? extends T>> fallback here, as that way we also support non-lambda function arguments.

@@ -676,6 +676,19 @@ Flux<T> after(Flux<T> flux) {
}
}

/** Drop redundant {@link Class#isInstance} in {@link Mono#onErrorResume(Function)}. */
Copy link
Member

Choose a reason for hiding this comment

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

Mono#onErrorResume(Function) isn't the overload that's invoked 🙃

@@ -676,6 +676,19 @@ Flux<T> after(Flux<T> flux) {
}
}

/** Drop redundant {@link Class#isInstance} in {@link Mono#onErrorResume(Function)}. */
static final class MonoOnErrorResume<T> {
Copy link
Member

Choose a reason for hiding this comment

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

We should add similar rules for a few other overload pairs that accept a Class and a Predicate. And likewise for Flux :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Phew 😆
That's quite a lot that you added :D
I was wondering indeed if there was a set of those methods that we should cover 😬
Guess that was the case 😅
Thanks ;) I could've done it though ;)

Copy link
Member

Choose a reason for hiding this comment

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

No worries!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Appreciating the fallback Function though, I was trying to find a nice way to do it, this is definitely cleaner.

@BeforeTemplate
Mono<T> before(
Mono<T> mono, Class<? extends Throwable> clazz, Consumer<? super Throwable> onError) {
return mono.doOnError(clazz::isInstance, onError);
Copy link
Member

Choose a reason for hiding this comment

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

Next to clazz::isInstance users may also write t -> t instanceof clazz. Rather than adding Refaster.anyOf in a bunch of places, let's instead add a BugChecker that maps the latter to the former. (For technical reasons IIUC we can't do this with Refaster.)

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'll work on this on a separate PR 👌

Copy link
Member

Choose a reason for hiding this comment

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

... and that PR is #323 :)

@rickie rickie added this to the 0.5.0 milestone Oct 28, 2022
@Stephan202 Stephan202 force-pushed the bdiederichs/drop-redundant-is-instance branch from 1d0e338 to 8e061ba Compare October 29, 2022 11:20
@Ptijohn Ptijohn force-pushed the bdiederichs/drop-redundant-is-instance branch from 8e061ba to 809beb2 Compare October 29, 2022 13:42
@rickie rickie force-pushed the bdiederichs/drop-redundant-is-instance branch from 809beb2 to c73bd48 Compare October 30, 2022 15:34
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

Changes LGTM!

Nice @Stephan202 that you added even more cases :).

@rickie
Copy link
Member

rickie commented Oct 30, 2022

Will merge once 🟢!

@rickie rickie changed the title Drop redundant ::isInstance in onErrorResume Introduce assorted Reactor error handling Refaster rules Oct 30, 2022
@rickie rickie merged commit b780c05 into master Oct 30, 2022
@rickie rickie deleted the bdiederichs/drop-redundant-is-instance branch October 30, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants