Skip to content

Commit

Permalink
ENH: use a error variable not a custom error type
Browse files Browse the repository at this point in the history
  • Loading branch information
sasaki77 committed Jan 19, 2024
1 parent 5047ab3 commit b419cbd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
9 changes: 1 addition & 8 deletions pkg/archiverappliance/aaclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ type AAclient struct {
baseURL string
}

type EmptyResponseError struct {
}

func (e *EmptyResponseError) Error() string {
return "response is empty"
}

func NewAAClient(ctx context.Context, url string) (*AAclient, error) {
return &AAclient{
baseURL: url,
Expand Down Expand Up @@ -163,7 +156,7 @@ func archiverSingleQueryParser(jsonAsBytes []byte) (models.SingleData, error) {

if len(response) < 1 {
log.DefaultLogger.Warn("Response is empty")
return sD, &EmptyResponseError{}
return sD, errEmptyResponse
}

var d models.DataResponse
Expand Down
7 changes: 7 additions & 0 deletions pkg/archiverappliance/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package archiverappliance

import "errors"

var (
errEmptyResponse = errors.New("response is empty")
)
3 changes: 1 addition & 2 deletions pkg/archiverappliance/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ responseCollector:
select {
case response := <-responsePipe:
if response.err != nil {
emptyError := &EmptyResponseError{}
if qm.IgnoreEmptyErr && errors.Is(response.err, emptyError) {
if qm.IgnoreEmptyErr && errors.Is(response.err, errEmptyResponse) {
continue
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/archiverappliance/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (f fakeClient) ExecuteSingleQuery(target string, qm models.ArchiverQueryMod
return models.SingleData{}, errors.New("test error")
}
if target == "emptyErr" {
return models.SingleData{}, &EmptyResponseError{}
return models.SingleData{}, errEmptyResponse
}

var v models.Values
Expand Down Expand Up @@ -534,8 +534,7 @@ func TestQueryWithEmptyResponse(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
result := Query(testCase.ctx, f, testCase.req, testCase.config)
res := result.Responses["A"]
emptyError := &EmptyResponseError{}
if !errors.Is(res.Error, emptyError) {
if !errors.Is(res.Error, errEmptyResponse) {
t.Errorf("An unexpected error has occurred")
}
if len(res.Frames) != 1 {
Expand Down

0 comments on commit b419cbd

Please sign in to comment.