Skip to content

Commit 5e543d7

Browse files
authored
Merge pull request #21047 from huajianxiaowanzi/main
cleanup: remove redundant panicAlternativeStringer
2 parents afbc014 + 3553655 commit 5e543d7

File tree

2 files changed

+0
-39
lines changed

2 files changed

+0
-39
lines changed

server/etcdserver/util.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package etcdserver
1616

1717
import (
18-
"fmt"
1918
"time"
2019

2120
"go.etcd.io/etcd/client/pkg/v3/types"
@@ -96,21 +95,3 @@ func (nc *notifier) notify(err error) {
9695
nc.err = err
9796
close(nc.c)
9897
}
99-
100-
// panicAlternativeStringer wraps a fmt.Stringer, and if calling String() panics, calls the alternative instead.
101-
// This is needed to ensure logging slow v2 requests does not panic, which occurs when running integration tests
102-
// with the embedded server with github.com/golang/protobuf v1.4.0+. See https://github.com/etcd-io/etcd/issues/12197.
103-
type panicAlternativeStringer struct {
104-
stringer fmt.Stringer
105-
alternative func() string
106-
}
107-
108-
func (n panicAlternativeStringer) String() (s string) {
109-
defer func() {
110-
if err := recover(); err != nil {
111-
s = n.alternative()
112-
}
113-
}()
114-
s = n.stringer.String()
115-
return s
116-
}

server/etcdserver/util_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,3 @@ func (s *nopTransporterWithActiveTime) Stop() {}
9090
func (s *nopTransporterWithActiveTime) Pause() {}
9191
func (s *nopTransporterWithActiveTime) Resume() {}
9292
func (s *nopTransporterWithActiveTime) reset(am map[types.ID]time.Time) { s.activeMap = am }
93-
94-
func TestPanicAlternativeStringer(t *testing.T) {
95-
p := panicAlternativeStringer{alternative: func() string { return "alternative" }}
96-
97-
p.stringer = testStringerFunc(func() string { panic("here") })
98-
if s := p.String(); s != "alternative" {
99-
t.Fatalf("expected 'alternative', got %q", s)
100-
}
101-
102-
p.stringer = testStringerFunc(func() string { return "test" })
103-
if s := p.String(); s != "test" {
104-
t.Fatalf("expected 'test', got %q", s)
105-
}
106-
}
107-
108-
type testStringerFunc func() string
109-
110-
func (s testStringerFunc) String() string {
111-
return s()
112-
}

0 commit comments

Comments
 (0)