Skip to content

Commit

Permalink
Return errors if unable to connect to Brokers when determining versio…
Browse files Browse the repository at this point in the history
…n of commands (#130)
  • Loading branch information
Mongey authored Jun 14, 2020
1 parent e8530df commit 514d14c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kafka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ func NewClient(config *Config) (*Client, error) {
return client, err
}

client.populateAPIVersions()
return client, nil
err = client.populateAPIVersions()
return client, err
}

func (c *Client) SaramaClient() sarama.Client {
return c.client
}

func (c *Client) populateAPIVersions() {
func (c *Client) populateAPIVersions() error {
log.Printf("[DEBUG] retrieving supported APIs from broker: %s", c.config.BootstrapServers)
broker, err := c.client.Controller()
if err != nil {
log.Printf("[ERROR] Unable to populate supported API versions. Error retrieving controller: %s", err)
return
return err
}

resp, err := broker.ApiVersions(&sarama.ApiVersionsRequest{})
if err != nil {
log.Printf("[ERROR] Unable to populate supported API versions. %s", err)
return
return err
}

m := map[int]int{}
Expand All @@ -83,6 +83,8 @@ func (c *Client) populateAPIVersions() {
m[int(v.ApiKey)] = int(v.MaxVersion)
}
c.supportedAPIs = m

return nil
}

func (c *Client) DeleteTopic(t string) error {
Expand Down

0 comments on commit 514d14c

Please sign in to comment.