Skip to content

Commit

Permalink
panic in describeconfigs merge when unknown type is received
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen2 committed Jun 3, 2022
1 parent e67bd5f commit 2cdf54a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
6 changes: 2 additions & 4 deletions protocol/describeconfigs/describeconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (r *Response) Merge(requests []protocol.Message, results []interface{}) (
return nil, v

default:
return nil, fmt.Errorf("Unknown result type: %T", result)
panic(fmt.Sprintf("unknown result type in Merge: %T", result))
}
}

Expand Down Expand Up @@ -132,6 +132,4 @@ type ResponseConfigSynonym struct {
ConfigSource int8 `kafka:"min=v1,max=v3"`
}

var (
_ protocol.BrokerMessage = (*Request)(nil)
)
var _ protocol.BrokerMessage = (*Request)(nil)
19 changes: 19 additions & 0 deletions protocol/describeconfigs/describeconfigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,23 @@ func TestResponse_Merge(t *testing.T) {
t.Fatalf("wanted err io.EOF, got %v", err)
}
})

t.Run("panic with unexpected type", func(t *testing.T) {
defer func() {
msg := recover()
if msg != "unknown result type in Merge: string" {
t.Fatal("unexpected panic", msg)
}
}()
r := &Response{}

r1 := &Response{
Resources: []ResponseResource{
{ResourceName: "r1"},
},
}

_, _ = r.Merge([]protocol.Message{&Request{}}, []interface{}{r1, "how did a string got here"})
t.Fatal("did not panic")
})
}

0 comments on commit 2cdf54a

Please sign in to comment.