Skip to content

Commit

Permalink
PSM-1627 Create refaster template to rewrite `.onErrorResume(e -> Mon…
Browse files Browse the repository at this point in the history
…o.empty())` to `.onErrorComplete()`

Add a new refaster template rule that rewrites `.onErrorResume(e -> Mono.empty())` to `.onErrorComplete()`. This is applied to `.onErrorResume(e -> Flux.empty())` as well.
  • Loading branch information
chamil-prabodha authored and Stephan202 committed Oct 6, 2022
1 parent 9af50d7 commit ffa4c51
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,32 @@ Flux<S> after(Flux<T> flux) {
}
}

/** Prefer {@link Flux#onErrorComplete()} over more contrived alternatives */
static final class FluxOnErrorComplete<T> {
@BeforeTemplate
Flux<T> before(Flux<T> flux) {
return flux.onErrorResume(e -> Flux.empty());
}

@AfterTemplate
Flux<T> after(Flux<T> flux) {
return flux.onErrorComplete();
}
}

/** Prefer {@link Mono#onErrorComplete()} over more contrived alternatives */
static final class MonoOnErrorComplete<T> {
@BeforeTemplate
Mono<T> before(Mono<T> mono) {
return mono.onErrorResume(e -> Mono.empty());
}

@AfterTemplate
Mono<T> after(Mono<T> mono) {
return mono.onErrorComplete();
}
}

/** Prefer {@link PublisherProbe#empty()}} over more verbose alternatives. */
static final class PublisherProbeEmpty<T> {
@BeforeTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ Flux<Number> testFluxCast() {
return Flux.just(1).map(Number.class::cast);
}

Flux<Object> testFluxOnErrorComplete() {
return Flux.error(new IllegalStateException()).onErrorResume(e -> Flux.empty());
}

Mono<Object> testMonoOnErrorComplete() {
return Mono.error(new IllegalStateException()).onErrorResume(e -> Mono.empty());
}

ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.of(Mono.empty()), PublisherProbe.of(Flux.empty()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ Flux<Number> testFluxCast() {
return Flux.just(1).cast(Number.class);
}

Flux<Object> testFluxOnErrorComplete() {
return Flux.error(new IllegalStateException()).onErrorComplete();
}

Mono<Object> testMonoOnErrorComplete() {
return Mono.error(new IllegalStateException()).onErrorComplete();
}

ImmutableSet<PublisherProbe<Void>> testPublisherProbeEmpty() {
return ImmutableSet.of(PublisherProbe.empty(), PublisherProbe.empty());
}
Expand Down

0 comments on commit ffa4c51

Please sign in to comment.