Skip to content

Commit

Permalink
Add default methods for exceptionToFailure and failureToException (#1809
Browse files Browse the repository at this point in the history
)

Add default methods for exceptionToFailure and failureToException
  • Loading branch information
Quinn-With-Two-Ns committed Jul 10, 2023
1 parent 15337d9 commit 25387be
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Defaults;
import com.google.common.base.Preconditions;
import io.temporal.api.common.v1.Payload;
import io.temporal.api.common.v1.Payloads;
import io.temporal.api.failure.v1.Failure;
import io.temporal.common.Experimental;
import io.temporal.failure.DefaultFailureConverter;
import io.temporal.failure.TemporalFailure;
import io.temporal.payload.codec.PayloadCodec;
import io.temporal.payload.context.SerializationContext;
Expand Down Expand Up @@ -174,7 +176,10 @@ default Object[] fromPayloads(
* @throws NullPointerException if failure is null
*/
@Nonnull
TemporalFailure failureToException(@Nonnull Failure failure);
default TemporalFailure failureToException(@Nonnull Failure failure) {
Preconditions.checkNotNull(failure, "failure");
return new DefaultFailureConverter().failureToException(failure, this);
}

/**
* Serialize an existing Throwable object into a Failure object. The default implementation
Expand All @@ -185,7 +190,10 @@ default Object[] fromPayloads(
* @throws NullPointerException if throwable is null
*/
@Nonnull
Failure exceptionToFailure(@Nonnull Throwable throwable);
default Failure exceptionToFailure(@Nonnull Throwable throwable) {
Preconditions.checkNotNull(throwable, "throwable");
return new DefaultFailureConverter().exceptionToFailure(throwable, this);
}

/**
* A correct implementation of this interface should have a fully functional "contextless"
Expand Down

0 comments on commit 25387be

Please sign in to comment.