Skip to content

Throw wrapped TimeoutException on Mono.block* and Flux.block*#3733

Merged
chemicL merged 2 commits intoreactor:mainfrom
injae-kim:block-throw-wrapped-timeout-exception
Mar 5, 2024
Merged

Throw wrapped TimeoutException on Mono.block* and Flux.block*#3733
chemicL merged 2 commits intoreactor:mainfrom
injae-kim:block-throw-wrapped-timeout-exception

Conversation

@injae-kim
Copy link
Contributor

Throw wrapped TimeoutException on Mono.block* and Flux.block* so that user can use this when timeout instead of digging into IllegalStateException message.

Fixes #3709.

Throw wrapped `TimeoutException` on `Mono.block*` and `Flux.block*` so that user can use this when timeout instead of digging into IllegalStateException message.

Fixes reactor#3709.
@injae-kim injae-kim requested a review from a team as a code owner February 22, 2024 16:33
Comment on lines +128 to +129
String errorMessage = "Timeout on blocking read for " + timeout + " " + unit;
throw new IllegalStateException(errorMessage, new TimeoutException(errorMessage));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public final T blockFirst(Duration timeout) {

public final T blockLast(Duration timeout) {

I checked that Mono#block(timeout), Flux#blockFirst(timeout), Flux#blockLast(timeout) use this code~!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* If the provided timeout expires, a {@link RuntimeException} is thrown.

// AS-IS
If the provided timeout expires, a {@link RuntimeException} is thrown.

// TO-BE
If the provided timeout expires, a {@link RuntimeException} is thrown with {@link TimeoutException} as the cause.

(just curiosity) should we enhance document on Mono#block*, Flux#block* like above?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ update javadoc :)

Comment on lines +152 to +153
String errorMessage = "Timeout on blocking read for " + timeout + " " + unit;
throw new IllegalStateException(errorMessage, new TimeoutException(errorMessage));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

public Optional<T> blockOptional(Duration timeout) {

I checked that Mono.blockOptional(timeout) use this code~!

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

Thanks @injae-kim ! Great job. Do you mind adding the bit about the cause to the javadocs as you suggested?

Comment on lines +128 to +129
String errorMessage = "Timeout on blocking read for " + timeout + " " + unit;
throw new IllegalStateException(errorMessage, new TimeoutException(errorMessage));
Copy link
Member

Choose a reason for hiding this comment

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

Yes, please.

.isThrownBy(() -> source.blockOptional(Duration.ofNanos(100)))
.withMessage("Timeout on blocking read for 100 NANOSECONDS");
.withMessage("Timeout on blocking read for 100 NANOSECONDS")
.withCause(new TimeoutException("Timeout on blocking read for 100 NANOSECONDS"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Update the Javadoc too

Copy link
Member

@chemicL chemicL left a comment

Choose a reason for hiding this comment

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

Thank you, @injae-kim 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type/enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeout behavior in Mono.block(timeout)

3 participants