Skip to content

Commit 7b21b77

Browse files
committed
fix: replace panic with error handling in compatUnaryServerInterceptor
1 parent 64d9466 commit 7b21b77

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

protocol/triple/triple_protocol/handler_compat.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
)
2626

2727
import (
28+
"github.com/dubbogo/gost/log/logger"
2829
"github.com/dubbogo/grpc-go"
2930
"github.com/dubbogo/grpc-go/metadata"
3031
"github.com/dubbogo/grpc-go/status"
@@ -64,13 +65,13 @@ func (t *tripleCompatInterceptor) compatUnaryServerInterceptor(ctx context.Conte
6465
}
6566
dubbo3RespRaw, err := handler(ctx, typed.Any())
6667
if dubbo3RespRaw == nil && err == nil {
67-
// This is going to panic during serialization. Debugging is much easier
68-
// if we panic here instead, so we can include the procedure name.
69-
panic(fmt.Sprintf("%s returned nil resp and nil error", t.procedure)) //nolint: forbidigo
68+
logger.Errorf("Procedure %s unexpectedly returned both nil response and nil error, which should not happen", t.procedure)
69+
return nil, errorf(CodeInternal, "Procedure %s unexpectedly returned both nil response and nil error, which should not happen", t.procedure)
7070
}
7171
dubbo3Resp, ok := dubbo3RespRaw.(*dubbo_protocol.RPCResult)
7272
if !ok {
73-
panic(fmt.Sprintf("%+v is not of type *RPCResult", dubbo3RespRaw))
73+
logger.Errorf("Procedure %s returned an unexpected response type. Expected *dubbo_protocol.RPCResult, but got %T", t.procedure, dubbo3RespRaw)
74+
return nil, errorf(CodeInternal, "Procedure %s returned an unexpected response type. Expected *dubbo_protocol.RPCResult, but got %T", t.procedure, dubbo3RespRaw)
7475
}
7576
dubbo3Err, ok := compatError(err)
7677
if ok {

0 commit comments

Comments
 (0)