diff --git a/http/handler.go b/http/handler.go index 3226eee50..5b79deef6 100644 --- a/http/handler.go +++ b/http/handler.go @@ -347,7 +347,7 @@ func (r *successResponse) check(err error) (statusCode int) { } r.Success = false - r.Error = &Error{Message: cause.Error()} + r.Error = &Error{Message: err.Error()} return statusCode } diff --git a/index.go b/index.go index e94692288..da749ff2d 100644 --- a/index.go +++ b/index.go @@ -155,7 +155,7 @@ func (i *Index) openFields() error { fld, err := i.newField(i.fieldPath(filepath.Base(fi.Name())), filepath.Base(fi.Name())) if err != nil { - return ErrName + return errors.Wrapf(ErrName, "'%s'", fi.Name()) } if err := fld.Open(); err != nil { return fmt.Errorf("open field: name=%s, err=%s", fld.Name(), err) diff --git a/pilosa.go b/pilosa.go index f8989e9b7..d410e1fd4 100644 --- a/pilosa.go +++ b/pilosa.go @@ -16,8 +16,9 @@ package pilosa import ( "encoding/json" - "errors" "regexp" + + "github.com/pkg/errors" ) // System errors. @@ -152,7 +153,7 @@ const TimeFormat = "2006-01-02T15:04" // validateName ensures that the name is a valid format. func validateName(name string) error { if !nameRegexp.Match([]byte(name)) { - return ErrName + return errors.Wrapf(ErrName, "'%s'", name) } return nil } diff --git a/server/handler_test.go b/server/handler_test.go index d6c5e49ae..ff9654933 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -690,9 +690,9 @@ func TestHandler_Endpoints(t *testing.T) { r = test.MustNewHTTPRequest("POST", "/index/idx1", strings.NewReader("")) h.ServeHTTP(w, r) if w.Code != gohttp.StatusConflict { - t.Fatalf("unexpected status code: %d", w.Code) - } else if w.Body.String() != `{"success":false,"error":{"message":"index already exists"}}`+"\n" { - t.Fatalf("unexpected body: %q", w.Body.String()) + t.Errorf("unexpected status code: %d", w.Code) + } else if w.Body.String() != `{"success":false,"error":{"message":"creating index: index already exists"}}`+"\n" { + t.Errorf("unexpected body: %q", w.Body.String()) } // create field @@ -710,9 +710,9 @@ func TestHandler_Endpoints(t *testing.T) { r = test.MustNewHTTPRequest("POST", "/index/idx1/field/fld1", strings.NewReader("")) h.ServeHTTP(w, r) if w.Code != gohttp.StatusConflict { - t.Fatalf("unexpected status code: %d", w.Code) - } else if w.Body.String() != `{"success":false,"error":{"message":"field already exists"}}`+"\n" { - t.Fatalf("unexpected body: %q", w.Body.String()) + t.Errorf("unexpected status code: %d", w.Code) + } else if w.Body.String() != `{"success":false,"error":{"message":"creating field: field already exists"}}`+"\n" { + t.Errorf("unexpected body: %q", w.Body.String()) } // delete field @@ -730,9 +730,9 @@ func TestHandler_Endpoints(t *testing.T) { r = test.MustNewHTTPRequest("DELETE", "/index/idx1/field/fld1", strings.NewReader("")) h.ServeHTTP(w, r) if w.Code != gohttp.StatusNotFound { - t.Fatalf("unexpected status code: %d", w.Code) - } else if w.Body.String() != `{"success":false,"error":{"message":"field not found"}}`+"\n" { - t.Fatalf("unexpected body: %q", w.Body.String()) + t.Errorf("unexpected status code: %d", w.Code) + } else if w.Body.String() != `{"success":false,"error":{"message":"deleting field: field not found"}}`+"\n" { + t.Errorf("unexpected body: %q", w.Body.String()) } // delete index @@ -750,9 +750,9 @@ func TestHandler_Endpoints(t *testing.T) { r = test.MustNewHTTPRequest("DELETE", "/index/idx1", strings.NewReader("")) h.ServeHTTP(w, r) if w.Code != gohttp.StatusNotFound { - t.Fatalf("unexpected status code: %d", w.Code) - } else if w.Body.String() != `{"success":false,"error":{"message":"index not found"}}`+"\n" { - t.Fatalf("unexpected body: %q", w.Body.String()) + t.Errorf("unexpected status code: %d", w.Code) + } else if w.Body.String() != `{"success":false,"error":{"message":"deleting index: index not found"}}`+"\n" { + t.Errorf("unexpected body: %q", w.Body.String()) } })