Skip to content

Commit 8beaa03

Browse files
committed
chore: update ZeroCopyResponseMarshaller to no longer have its error message hard coded to ReadObject
1 parent ff8fd8f commit 8beaa03

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
import io.grpc.ManagedChannelBuilder;
9898
import io.grpc.MethodDescriptor;
9999
import io.grpc.Status;
100+
import io.grpc.StatusRuntimeException;
100101
import io.grpc.protobuf.ProtoUtils;
101102
import io.opentelemetry.api.OpenTelemetry;
102103
import java.io.Closeable;
@@ -1214,21 +1215,15 @@ public Response parse(InputStream stream) {
12141215
cis.setSizeLimit(Integer.MAX_VALUE);
12151216
}
12161217
} catch (IOException e) {
1217-
throw Status.INTERNAL
1218-
.withDescription("Error parsing input stream for ReadObject")
1219-
.withCause(e)
1220-
.asRuntimeException();
1218+
throw createStatusRuntimeException(e);
12211219
}
12221220
if (cis != null) {
12231221
// fast path (no memory copy)
12241222
Response message;
12251223
try {
12261224
message = parseFrom(cis);
12271225
} catch (InvalidProtocolBufferException ipbe) {
1228-
throw Status.INTERNAL
1229-
.withDescription("Invalid protobuf byte sequence for ReadObject")
1230-
.withCause(ipbe)
1231-
.asRuntimeException();
1226+
throw createStatusRuntimeException(ipbe);
12321227
}
12331228
unclosedStreams.put(message, stream);
12341229
return message;
@@ -1238,6 +1233,18 @@ public Response parse(InputStream stream) {
12381233
}
12391234
}
12401235

1236+
private StatusRuntimeException createStatusRuntimeException(IOException e) {
1237+
String description = "";
1238+
Response messagePrototype = baseMarshaller.getMessagePrototype();
1239+
if (messagePrototype != null) {
1240+
description = "for " + messagePrototype.getClass().getSimpleName();
1241+
}
1242+
return Status.INTERNAL
1243+
.withDescription("Error parsing input stream" + description)
1244+
.withCause(e)
1245+
.asRuntimeException();
1246+
}
1247+
12411248
private Response parseFrom(CodedInputStream stream) throws InvalidProtocolBufferException {
12421249
Response message = parser.parseFrom(stream);
12431250
try {

0 commit comments

Comments
 (0)