Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit ffec269

Browse files
authored
Merge pull request #1943 from jaffee/error-context
return orig error instead of cause in handler
2 parents 000c188 + 2414c71 commit ffec269

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

http/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func (r *successResponse) check(err error) (statusCode int) {
347347
}
348348

349349
r.Success = false
350-
r.Error = &Error{Message: cause.Error()}
350+
r.Error = &Error{Message: err.Error()}
351351

352352
return statusCode
353353
}

index.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (i *Index) openFields() error {
155155

156156
fld, err := i.newField(i.fieldPath(filepath.Base(fi.Name())), filepath.Base(fi.Name()))
157157
if err != nil {
158-
return ErrName
158+
return errors.Wrapf(ErrName, "'%s'", fi.Name())
159159
}
160160
if err := fld.Open(); err != nil {
161161
return fmt.Errorf("open field: name=%s, err=%s", fld.Name(), err)

pilosa.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ package pilosa
1616

1717
import (
1818
"encoding/json"
19-
"errors"
2019
"regexp"
20+
21+
"github.com/pkg/errors"
2122
)
2223

2324
// System errors.
@@ -152,7 +153,7 @@ const TimeFormat = "2006-01-02T15:04"
152153
// validateName ensures that the name is a valid format.
153154
func validateName(name string) error {
154155
if !nameRegexp.Match([]byte(name)) {
155-
return ErrName
156+
return errors.Wrapf(ErrName, "'%s'", name)
156157
}
157158
return nil
158159
}

server/handler_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,9 @@ func TestHandler_Endpoints(t *testing.T) {
690690
r = test.MustNewHTTPRequest("POST", "/index/idx1", strings.NewReader(""))
691691
h.ServeHTTP(w, r)
692692
if w.Code != gohttp.StatusConflict {
693-
t.Fatalf("unexpected status code: %d", w.Code)
694-
} else if w.Body.String() != `{"success":false,"error":{"message":"index already exists"}}`+"\n" {
695-
t.Fatalf("unexpected body: %q", w.Body.String())
693+
t.Errorf("unexpected status code: %d", w.Code)
694+
} else if w.Body.String() != `{"success":false,"error":{"message":"creating index: index already exists"}}`+"\n" {
695+
t.Errorf("unexpected body: %q", w.Body.String())
696696
}
697697

698698
// create field
@@ -710,9 +710,9 @@ func TestHandler_Endpoints(t *testing.T) {
710710
r = test.MustNewHTTPRequest("POST", "/index/idx1/field/fld1", strings.NewReader(""))
711711
h.ServeHTTP(w, r)
712712
if w.Code != gohttp.StatusConflict {
713-
t.Fatalf("unexpected status code: %d", w.Code)
714-
} else if w.Body.String() != `{"success":false,"error":{"message":"field already exists"}}`+"\n" {
715-
t.Fatalf("unexpected body: %q", w.Body.String())
713+
t.Errorf("unexpected status code: %d", w.Code)
714+
} else if w.Body.String() != `{"success":false,"error":{"message":"creating field: field already exists"}}`+"\n" {
715+
t.Errorf("unexpected body: %q", w.Body.String())
716716
}
717717

718718
// delete field
@@ -730,9 +730,9 @@ func TestHandler_Endpoints(t *testing.T) {
730730
r = test.MustNewHTTPRequest("DELETE", "/index/idx1/field/fld1", strings.NewReader(""))
731731
h.ServeHTTP(w, r)
732732
if w.Code != gohttp.StatusNotFound {
733-
t.Fatalf("unexpected status code: %d", w.Code)
734-
} else if w.Body.String() != `{"success":false,"error":{"message":"field not found"}}`+"\n" {
735-
t.Fatalf("unexpected body: %q", w.Body.String())
733+
t.Errorf("unexpected status code: %d", w.Code)
734+
} else if w.Body.String() != `{"success":false,"error":{"message":"deleting field: field not found"}}`+"\n" {
735+
t.Errorf("unexpected body: %q", w.Body.String())
736736
}
737737

738738
// delete index
@@ -750,9 +750,9 @@ func TestHandler_Endpoints(t *testing.T) {
750750
r = test.MustNewHTTPRequest("DELETE", "/index/idx1", strings.NewReader(""))
751751
h.ServeHTTP(w, r)
752752
if w.Code != gohttp.StatusNotFound {
753-
t.Fatalf("unexpected status code: %d", w.Code)
754-
} else if w.Body.String() != `{"success":false,"error":{"message":"index not found"}}`+"\n" {
755-
t.Fatalf("unexpected body: %q", w.Body.String())
753+
t.Errorf("unexpected status code: %d", w.Code)
754+
} else if w.Body.String() != `{"success":false,"error":{"message":"deleting index: index not found"}}`+"\n" {
755+
t.Errorf("unexpected body: %q", w.Body.String())
756756
}
757757
})
758758

0 commit comments

Comments
 (0)