From 7a6cba805e87494abce0fddaa4f84fb50399c8d9 Mon Sep 17 00:00:00 2001 From: Tim Raymond Date: Mon, 19 Sep 2016 10:09:53 -0400 Subject: [PATCH] Rework domain errs to be strings At @goller's recommendation, we're following @benbjohnson's advice laid out here: https://github.com/benbjohnson/wtf/blob/master/errors.go and moving errors to the top level package. This cleaned up some ugliness in the tests where we needed to type assert. --- errors.go | 13 +++++++++++++ influx/errors.go | 13 ------------- influx/influx.go | 2 +- influx/influx_test.go | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 errors.go delete mode 100644 influx/errors.go diff --git a/errors.go b/errors.go new file mode 100644 index 0000000000..9bfa163ff1 --- /dev/null +++ b/errors.go @@ -0,0 +1,13 @@ +package mrfusion + +// General errors. +const ( + ErrUpstreamTimeout = Error("request to backend timed out") +) + +// Error is a domain error encountered while processing mrfusion requests +type Error string + +func (e Error) Error() string { + return string(e) +} diff --git a/influx/errors.go b/influx/errors.go deleted file mode 100644 index b7b95a1a20..0000000000 --- a/influx/errors.go +++ /dev/null @@ -1,13 +0,0 @@ -package influx - -const ( - ErrTimedOut string = "Timeout during request to InfluxDB" -) - -// TimeoutError is returned when requests to InfluxDB are cancelled or time -// out. -type TimeoutError struct{} - -func (te TimeoutError) Error() string { - return ErrTimedOut -} diff --git a/influx/influx.go b/influx/influx.go index 2bc49bb8e4..3706e7eb71 100644 --- a/influx/influx.go +++ b/influx/influx.go @@ -45,7 +45,7 @@ func (c *Client) Query(ctx context.Context, query mrfusion.Query) (mrfusion.Resp case resp := <-resps: return resp, resp.err case <-ctx.Done(): - return nil, TimeoutError{} + return nil, mrfusion.ErrUpstreamTimeout } } diff --git a/influx/influx_test.go b/influx/influx_test.go index f7273f06ba..7f16d4e945 100644 --- a/influx/influx_test.go +++ b/influx/influx_test.go @@ -79,7 +79,7 @@ func Test_Influx_CancelsInFlightRequests(t *testing.T) { } err := <-errs - if _, ok := err.(influx.TimeoutError); !ok { - t.Error("Expected TimeoutError but wasn't. err was", err) + if err != mrfusion.ErrUpstreamTimeout { + t.Error("Expected timeout error but wasn't. err was", err) } }