From c763db96444d618b037d726de8e40bcfae60cd34 Mon Sep 17 00:00:00 2001 From: Maxime mouial Date: Thu, 30 Apr 2020 15:29:50 -0600 Subject: [PATCH] Fix CloneWithExtraOptions panic when given a nil client --- statsd/client_test.go | 4 ++++ statsd/statsd.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/statsd/client_test.go b/statsd/client_test.go index e0da0f2b7..386f4dc48 100644 --- a/statsd/client_test.go +++ b/statsd/client_test.go @@ -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 diff --git a/statsd/statsd.go b/statsd/statsd.go index e8df59e31..85e7935d5 100644 --- a/statsd/statsd.go +++ b/statsd/statsd.go @@ -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") }