This is an automated email from the ASF dual-hosted git repository.
AlexStocks 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 a3634343f fix: preserve wrapped error handling (#3580)
a3634343f is described below
commit a3634343fcd9c1bd97e0603157610a77b4fb89cc
Author: nightcityblade <[email protected]>
AuthorDate: Sun Aug 2 22:10:53 2026 +0800
fix: preserve wrapped error handling (#3580)
* fix: preserve wrapped error handling
Use errors.Is for sentinel error checks and retain exporter error chains
with %w.
Fixes: #3560
Signed-off-by: nightcityblade <[email protected]>
* test: cover wrapped error handling
* chore: format reflection test
---------
Signed-off-by: nightcityblade <[email protected]>
Co-authored-by: nightcityblade <[email protected]>
---
otel/trace/exporter.go | 2 +-
otel/trace/exporter_test.go | 4 +-
protocol/jsonrpc/server.go | 5 ++-
protocol/triple/reflection/serverreflection.go | 3 +-
.../triple/reflection/serverreflection_test.go | 49 ++++++++++++++++++++++
5 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/otel/trace/exporter.go b/otel/trace/exporter.go
index 7f2292a63..61e9e4adf 100644
--- a/otel/trace/exporter.go
+++ b/otel/trace/exporter.go
@@ -74,7 +74,7 @@ func NewExporter(config *ExporterConfig, customFunc func()
(sdktrace.SpanExporte
exporter, err := customFunc()
if err != nil {
- err = fmt.Errorf("failed to create %s exporter: %v",
config.Exporter, err)
+ err = fmt.Errorf("failed to create %s exporter: %w",
config.Exporter, err)
logger.Errorf("[OTel][Trace] failed to create %s exporter,
err=%v", config.Exporter, err)
return
}
diff --git a/otel/trace/exporter_test.go b/otel/trace/exporter_test.go
index 750fc9acd..941a838bc 100644
--- a/otel/trace/exporter_test.go
+++ b/otel/trace/exporter_test.go
@@ -76,8 +76,9 @@ func TestNewExporter_CustomFuncError(t *testing.T) {
ServiceName: "test-service",
}
+ cause := errors.New("custom func error")
customFunc := func() (sdktrace.SpanExporter, error) {
- return nil, errors.New("custom func error")
+ return nil, cause
}
tracerProvider, propagator, err := NewExporter(config, customFunc)
@@ -85,6 +86,7 @@ func TestNewExporter_CustomFuncError(t *testing.T) {
assert.Nil(t, propagator)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to create test exporter")
+ require.ErrorIs(t, err, cause)
}
func TestNewExporter_InvalidSampleMode(t *testing.T) {
diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go
index 7a9d44d95..90dcae027 100644
--- a/protocol/jsonrpc/server.go
+++ b/protocol/jsonrpc/server.go
@@ -21,6 +21,7 @@ import (
"bufio"
"bytes"
"context"
+ "errors"
"io"
"mime"
"net"
@@ -124,7 +125,7 @@ func (s *Server) handlePkg(conn net.Conn) {
for {
bufReader := bufio.NewReader(io.LimitReader(conn,
MaxHeaderSize))
- if _, err := bufReader.Peek(1); err == io.EOF {
+ if _, err := bufReader.Peek(1); errors.Is(err, io.EOF) {
return
}
r, err := http.ReadRequest(bufReader)
@@ -326,7 +327,7 @@ func serveRequest(ctx context.Context, header
map[string]string, body []byte, co
codec := newServerCodec()
err := codec.ReadHeader(header, body)
if err != nil {
- if err == io.EOF || err == io.ErrUnexpectedEOF {
+ if errors.Is(err, io.EOF) || errors.Is(err,
io.ErrUnexpectedEOF) {
return perrors.WithStack(err)
}
return perrors.New("server cannot decode request: " +
err.Error())
diff --git a/protocol/triple/reflection/serverreflection.go
b/protocol/triple/reflection/serverreflection.go
index 2c701bf17..efb61468d 100644
--- a/protocol/triple/reflection/serverreflection.go
+++ b/protocol/triple/reflection/serverreflection.go
@@ -20,6 +20,7 @@ package reflection
import (
"context"
+ "errors"
"io"
"slices"
"sort"
@@ -166,7 +167,7 @@ func (s *ReflectionServer) ServerReflectionInfo(ctx
context.Context, stream rpb.
sentFileDescriptors := make(map[string]bool)
for {
in, err := stream.Recv()
- if err == io.EOF {
+ if errors.Is(err, io.EOF) {
return nil
}
if err != nil {
diff --git a/protocol/triple/reflection/serverreflection_test.go
b/protocol/triple/reflection/serverreflection_test.go
new file mode 100644
index 000000000..8706d5c02
--- /dev/null
+++ b/protocol/triple/reflection/serverreflection_test.go
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package reflection
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "io"
+ "testing"
+)
+
+import (
+ "github.com/stretchr/testify/require"
+)
+
+import (
+ rpb
"dubbo.apache.org/dubbo-go/v3/protocol/triple/reflection/triple_reflection"
+)
+
+type recvErrorStream struct {
+ rpb.ServerReflection_ServerReflectionInfoServer
+ err error
+}
+
+func (s recvErrorStream) Recv() (*rpb.ServerReflectionRequest, error) { return
nil, s.err }
+
+func TestServerReflectionInfoRecvError(t *testing.T) {
+ server := &ReflectionServer{}
+ require.NoError(t, server.ServerReflectionInfo(context.Background(),
recvErrorStream{err: fmt.Errorf("transport: %w", io.EOF)}))
+
+ recvErr := errors.New("receive failed")
+ require.ErrorIs(t, server.ServerReflectionInfo(context.Background(),
recvErrorStream{err: recvErr}), recvErr)
+}