Make ErrorStorage a concrete type not an interface

Since it is used in a type assertion, having it as an alias to the
error interface is the same as saying 'error', i.e. it succeeds for
all types of error.  Change to a struct which is a concrete type and
the type assertion will only succeed if the type is identical.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
Bryan Boreham 2018-09-18 19:34:00 +00:00
parent f033f48f74
commit 9a956872a3
2 changed files with 5 additions and 2 deletions

View File

@ -74,7 +74,7 @@ type (
ErrTooManySamples string ErrTooManySamples string
// ErrStorage is returned if an error was encountered in the storage layer // ErrStorage is returned if an error was encountered in the storage layer
// during query handling. // during query handling.
ErrStorage error ErrStorage struct{ error }
) )
func (e ErrQueryTimeout) Error() string { func (e ErrQueryTimeout) Error() string {
@ -86,6 +86,9 @@ func (e ErrQueryCanceled) Error() string {
func (e ErrTooManySamples) Error() string { func (e ErrTooManySamples) Error() string {
return fmt.Sprintf("query processing would load too many samples into memory in %s", string(e)) return fmt.Sprintf("query processing would load too many samples into memory in %s", string(e))
} }
func (e ErrStorage) Error() string {
return e.error.Error()
}
// A Query is derived from an a raw query string and can be run against an engine // A Query is derived from an a raw query string and can be run against an engine
// it is associated with. // it is associated with.

View File

@ -193,7 +193,7 @@ func TestQueryError(t *testing.T) {
Timeout: 10 * time.Second, Timeout: 10 * time.Second,
} }
engine := NewEngine(opts) engine := NewEngine(opts)
errStorage := ErrStorage(fmt.Errorf("storage error")) errStorage := ErrStorage{fmt.Errorf("storage error")}
queryable := storage.QueryableFunc(func(ctx context.Context, mint, maxt int64) (storage.Querier, error) { queryable := storage.QueryableFunc(func(ctx context.Context, mint, maxt int64) (storage.Querier, error) {
return &errQuerier{err: errStorage}, nil return &errQuerier{err: errStorage}, nil
}) })