Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 9e5bce5

Browse files
author
Yasss
authored
Merge pull request #42 from heetch/fix-panic
Fix panicking
2 parents 4aa9633 + 3327d2b commit 9e5bce5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

consumer/consumer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (c *Consumer) setup() {
8181
}
8282
}
8383

84-
if c.retryStrategy == nil {
84+
if c.config != nil && c.retryStrategy == nil {
8585
// Note: the logic in handleMsg assumes that
8686
// this does not terminate; be aware of that when changing
8787
// this strategy.
@@ -101,14 +101,14 @@ func (c *Consumer) setup() {
101101
// When Serve terminates it will return an Error or nil to indicate
102102
// that it excited without error.
103103
func (c *Consumer) Serve(config Config, addrs ...string) error {
104-
c.setup()
105-
106104
c.config = &config
107105
err := c.validateConfig()
108106
if err != nil {
109107
return err
110108
}
111109

110+
c.setup()
111+
112112
topics := c.handlers.Topics()
113113

114114
consumerGroup := fmt.Sprintf("%s-consumer-group", c.config.ClientID)
@@ -239,7 +239,8 @@ func (c *Consumer) handleMsg(msg *sarama.ConsumerMessage) (*Message, int) {
239239
}
240240
return m, attempts
241241
}
242-
panic("unreachable")
242+
return nil, attempts
243+
243244
}
244245

245246
// MetricsReporter is an interface that can be passed to set metrics hook to receive metrics

0 commit comments

Comments
 (0)