Skip to content

Commit e115414

Browse files
Copilotahmedmuhsin
andcommitted
Add detailed error logging in JavaWorkerClient onError handler
- Enhanced onError method to log gRPC stream errors with status code and description - Added handling for both StatusRuntimeException and StatusException - Maintained existing task.completeExceptionally(t) behavior - All existing tests pass successfully Co-authored-by: ahmedmuhsin <36454324+ahmedmuhsin@users.noreply.github.com>
1 parent 341b477 commit e115414

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/main/java/com/microsoft/azure/functions/worker/JavaWorkerClient.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,27 @@ public void onNext(StreamingMessage message) {
100100
public void onCompleted() { this.task.complete(null); }
101101

102102
@Override
103-
public void onError(Throwable t) { this.task.completeExceptionally(t); }
103+
public void onError(Throwable t) {
104+
Logger logger = Logger.getLogger(JavaWorkerClient.class.getName());
105+
String statusCode = "Unknown";
106+
String statusDescription = t.getMessage();
107+
108+
if (t instanceof io.grpc.StatusRuntimeException) {
109+
io.grpc.StatusRuntimeException sre = (io.grpc.StatusRuntimeException) t;
110+
statusCode = sre.getStatus().getCode().name();
111+
statusDescription = sre.getStatus().getDescription();
112+
} else if (t instanceof io.grpc.StatusException) {
113+
io.grpc.StatusException se = (io.grpc.StatusException) t;
114+
statusCode = se.getStatus().getCode().name();
115+
statusDescription = se.getStatus().getDescription();
116+
}
117+
118+
logger.severe(String.format(
119+
"gRPC stream error. StatusCode: %s, Description: %s, Exception: %s",
120+
statusCode, statusDescription, t.toString()));
121+
122+
this.task.completeExceptionally(t);
123+
}
104124

105125
private CompletableFuture<Void> getListeningTask() { return this.task; }
106126

0 commit comments

Comments
 (0)