This is an automated email from the ASF dual-hosted git repository.

Alanxtl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new e74a8d714 fix(triple): preserve CodeBizError over the Triple unary 
transport (#3655)
e74a8d714 is described below

commit e74a8d7143fa777b6a44b5fcea4acac7fe6da538
Author: anchor <[email protected]>
AuthorDate: Sun Aug 16 08:22:37 2026 +0800

    fix(triple): preserve CodeBizError over the Triple unary transport (#3655)
    
    Over the Triple (non-gRPC) unary transport, tripleWireError.asError()
    clamped any code outside [minCode, maxCode] to CodeUnknown, so a
    server-returned CodeBizError (17) reached the client as CodeUnknown (2).
    The clamp comes from connect-go, which only defines codes 1..16;
    CodeBizError is a dubbo-go extension and maxCode was never updated.
    code.go already goes out of its way to keep such codes intact, so that
    UnmarshalText round-trips them, and asError then discarded them again.
    
    As a result failover.isBizError stopped recognizing business errors and
    retried them, and metrics/rpc counted them as unknown failures. The gRPC
    transport was unaffected because grpcErrorFromTrailer does not clamp.
    
    Exempt CodeBizError from the clamp and add a regression test asserting
    the client-visible code over both transports.
    
    Fixes: #3654
    
    Assisted-by: Cursor (Claude Opus 5)
    
    Signed-off-by: codeAnqiang-ma 
<[email protected]>
    Co-authored-by: codeAnqiang-ma 
<[email protected]>
    Co-authored-by: Cursor <[email protected]>
---
 protocol/triple/triple_protocol/protocol_triple.go |  2 +-
 protocol/triple/triple_protocol/triple_ext_test.go | 38 ++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/protocol/triple/triple_protocol/protocol_triple.go 
b/protocol/triple/triple_protocol/protocol_triple.go
index a53f63f7a..5d322730b 100644
--- a/protocol/triple/triple_protocol/protocol_triple.go
+++ b/protocol/triple/triple_protocol/protocol_triple.go
@@ -691,7 +691,7 @@ func (e *tripleWireError) asError() *Error {
        if e == nil {
                return nil
        }
-       if e.Code < minCode || e.Code > maxCode {
+       if (e.Code < minCode || e.Code > maxCode) && e.Code != CodeBizError {
                e.Code = CodeUnknown
        }
        err := NewWireError(e.Code, errors.New(e.Message))
diff --git a/protocol/triple/triple_protocol/triple_ext_test.go 
b/protocol/triple/triple_protocol/triple_ext_test.go
index fb8b40e58..53a3356c0 100644
--- a/protocol/triple/triple_protocol/triple_ext_test.go
+++ b/protocol/triple/triple_protocol/triple_ext_test.go
@@ -710,6 +710,44 @@ func TestContextError(t *testing.T) {
        assert.False(t, triple.IsWireError(err))
 }
 
+func TestBizErrorCodePreservedAcrossProtocols(t *testing.T) {
+       t.Parallel()
+
+       handler := triple.NewUnaryHandler(
+               "/connect.ping.v1.PingService/Ping",
+               func() any { return new(pingv1.PingRequest) },
+               func(ctx context.Context, req *triple.Request) 
(*triple.Response, error) {
+                       return nil, triple.NewError(triple.CodeBizError, 
errors.New(errorMessage))
+               },
+       )
+       assertBizError := func(t *testing.T, server *httptest.Server, opts 
...triple.ClientOption) { //nolint:thelper
+               client := pingv1connect.NewPingServiceClient(server.Client(), 
server.URL, opts...)
+               request := triple.NewRequest(&pingv1.PingRequest{Number: 42})
+               response := triple.NewResponse(&pingv1.PingResponse{})
+               err := client.Ping(context.Background(), request, response)
+               assert.NotNil(t, err)
+               var tripleErr *triple.Error
+               assert.True(t, errors.As(err, &tripleErr))
+               assert.Equal(t, tripleErr.Code(), triple.CodeBizError)
+       }
+
+       t.Run("triple", func(t *testing.T) {
+               t.Parallel()
+               server := httptest.NewServer(handler)
+               t.Cleanup(server.Close)
+               assertBizError(t, server, triple.WithTriple())
+       })
+
+       t.Run("grpc", func(t *testing.T) {
+               t.Parallel()
+               server := httptest.NewUnstartedServer(handler)
+               server.EnableHTTP2 = true
+               server.StartTLS()
+               t.Cleanup(server.Close)
+               assertBizError(t, server)
+       })
+}
+
 func TestGRPCMarshalStatusError(t *testing.T) {
        t.Parallel()
 

Reply via email to