Skip to content

Commit 2cdf54a

Browse files
committed
panic in describeconfigs merge when unknown type is received
1 parent e67bd5f commit 2cdf54a

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

protocol/describeconfigs/describeconfigs.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (r *Response) Merge(requests []protocol.Message, results []interface{}) (
9999
return nil, v
100100

101101
default:
102-
return nil, fmt.Errorf("Unknown result type: %T", result)
102+
panic(fmt.Sprintf("unknown result type in Merge: %T", result))
103103
}
104104
}
105105

@@ -132,6 +132,4 @@ type ResponseConfigSynonym struct {
132132
ConfigSource int8 `kafka:"min=v1,max=v3"`
133133
}
134134

135-
var (
136-
_ protocol.BrokerMessage = (*Request)(nil)
137-
)
135+
var _ protocol.BrokerMessage = (*Request)(nil)

protocol/describeconfigs/describeconfigs_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,23 @@ func TestResponse_Merge(t *testing.T) {
5454
t.Fatalf("wanted err io.EOF, got %v", err)
5555
}
5656
})
57+
58+
t.Run("panic with unexpected type", func(t *testing.T) {
59+
defer func() {
60+
msg := recover()
61+
if msg != "unknown result type in Merge: string" {
62+
t.Fatal("unexpected panic", msg)
63+
}
64+
}()
65+
r := &Response{}
66+
67+
r1 := &Response{
68+
Resources: []ResponseResource{
69+
{ResourceName: "r1"},
70+
},
71+
}
72+
73+
_, _ = r.Merge([]protocol.Message{&Request{}}, []interface{}{r1, "how did a string got here"})
74+
t.Fatal("did not panic")
75+
})
5776
}

0 commit comments

Comments
 (0)