Skip to content

Commit

Permalink
Fix CloneWithExtraOptions panic when given a nil client
Browse files Browse the repository at this point in the history
  • Loading branch information
hush-hush committed Apr 30, 2020
1 parent 17f7bfc commit c763db9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions statsd/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ func TestNilError(t *testing.T) {
func() error { return c.SimpleEvent("", "") },
func() error { return c.ServiceCheck(statsd.NewServiceCheck("", statsd.Ok)) },
func() error { return c.SimpleServiceCheck("", statsd.Ok) },
func() error {
_, err := statsd.CloneWithExtraOptions(nil, statsd.WithChannelMode())
return err
},
}
for i, f := range tests {
var err error
Expand Down
4 changes: 4 additions & 0 deletions statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ func NewWithWriter(w statsdWriter, options ...Option) (*Client, error) {

// CloneWithExtraOptions create a new Client with extra options
func CloneWithExtraOptions(c *Client, options ...Option) (*Client, error) {
if c == nil {
return nil, ErrNoClient
}

if c.addrOption == "" {
return nil, fmt.Errorf("can't clone client with no addrOption")
}
Expand Down

0 comments on commit c763db9

Please sign in to comment.