Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
package io.temporal.serviceclient;

import com.google.common.base.Preconditions;
import com.google.protobuf.Any;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.*;
import com.google.rpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.protobuf.StatusProto;
Expand Down Expand Up @@ -74,14 +72,26 @@ public static <T extends GeneratedMessageV3> T getFailure(

/** Create StatusRuntimeException with given details. */
public static <T extends GeneratedMessageV3> StatusRuntimeException newException(
io.grpc.Status status, T details) {
io.grpc.Status status, T details, Descriptors.Descriptor detailsDescriptor) {
Preconditions.checkNotNull(status, "status cannot be null");
Status protoStatus =
Status.newBuilder()
.setCode(status.getCode().value())
.setMessage(status.getDescription())
.addDetails(Any.pack(details))
.addDetails(packAny(details, detailsDescriptor))
.build();
return StatusProto.toStatusRuntimeException(protoStatus);
}

/**
* This method does exactly what {@link Any#pack(Message)} does. But it doesn't go into reflection
* to fetch the {@code descriptor}, which allows us to avoid a bunch of Graal reflection configs.
*/
private static <T extends GeneratedMessageV3> Any packAny(
T details, Descriptors.Descriptor descriptor) {
return Any.newBuilder()
.setTypeUrl("type.googleapis.com/" + descriptor.getFullName())
.setValue(details.toByteString())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,8 @@ private static void completeQuery(
result.completeExceptionally(
StatusUtils.newException(
Status.INTERNAL.withDescription(value.getErrorMessage()),
QueryFailedFailure.getDefaultInstance()));
QueryFailedFailure.getDefaultInstance(),
QueryFailedFailure.getDescriptor()));
break;
default:
throw Status.INVALID_ARGUMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ public void completeWorkflowTask(
.completeExceptionally(
StatusUtils.newException(
Status.INTERNAL.withDescription(result.getErrorMessage()),
QueryFailedFailure.getDefaultInstance()));
QueryFailedFailure.getDefaultInstance(),
QueryFailedFailure.getDescriptor()));
break;
case UNRECOGNIZED:
throw Status.INVALID_ARGUMENT
Expand Down Expand Up @@ -2171,7 +2172,8 @@ public void completeQuery(QueryId queryId, RespondQueryTaskCompletedRequest comp
StatusRuntimeException error =
StatusUtils.newException(
Status.INVALID_ARGUMENT.withDescription(completeRequest.getErrorMessage()),
QueryFailedFailure.getDefaultInstance());
QueryFailedFailure.getDefaultInstance(),
QueryFailedFailure.getDescriptor());
result.completeExceptionally(error);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ private StartWorkflowExecutionResponse throwDuplicatedWorkflow(
Status.ALREADY_EXISTS.withDescription(
String.format(
"WorkflowId: %s, " + "RunId: %s", execution.getWorkflowId(), execution.getRunId())),
error);
error,
WorkflowExecutionAlreadyStartedFailure.getDescriptor());
}

private StartWorkflowExecutionResponse startWorkflowExecutionNoRunningCheckLocked(
Expand Down