Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Renamed PilosaError to Error; more go report fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yuce committed May 1, 2017
1 parent 1c045fe commit b27da62
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ response := client.Query(frame.Bitmap(5), options)

### Server Response

When a query is sent to a Pilosa server, the server either fulfills the query or sends an error message. In the case of an error, a `PilosaError` struct is returned, otherwise a `QueryResponse` struct is returned.
When a query is sent to a Pilosa server, the server either fulfills the query or sends an error message. In the case of an error, a `pilosa.Error` struct is returned, otherwise a `QueryResponse` struct is returned.

A `QueryResponse` struct may contain zero or more results of `QueryResult` type. You can access all results using the `Results` function of `QueryResponse` (which returns a list of `QueryResult` objects), or you can use the `Result` method (which returns either the first result or `nil` if there are no results):

Expand Down
9 changes: 4 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/golang/protobuf/proto"
"github.com/pilosa/go-pilosa/internal"
"io/ioutil"
"net"
"net/http"
"time"

"github.com/golang/protobuf/proto"
"github.com/pilosa/go-pilosa/internal"
)

// Pilosa HTTP Client
Expand Down Expand Up @@ -98,7 +97,7 @@ func (c *Client) Query(query PQLQuery, options *QueryOptions) (*QueryResponse, e
return nil, err
}
if !queryResponse.Success {
return nil, NewPilosaError(queryResponse.ErrorMessage)
return nil, NewError(queryResponse.ErrorMessage)
}
return queryResponse, nil
}
Expand Down Expand Up @@ -231,7 +230,7 @@ func (c *Client) httpRequest(method string, path string, data []byte, returnResp
if err != nil {
return nil, nil, err
}
return nil, nil, NewPilosaError(fmt.Sprintf("Server error (%d) %s: %s", response.StatusCode, response.Status, msg))
return nil, nil, NewError(fmt.Sprintf("Server error (%d) %s: %s", response.StatusCode, response.Status, msg))
}
if returnResponse == noResponse {
return nil, nil, nil
Expand Down
28 changes: 15 additions & 13 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,27 @@ import (
"fmt"
)

type PilosaError struct {
// Error contains a Pilosa specific error
type Error struct {
Message string
}

// NewPilosaError creates a Pilosa error
func NewPilosaError(message string) *PilosaError {
return &PilosaError{Message: message}
// NewError creates a Pilosa error
func NewError(message string) *Error {
return &Error{Message: message}
}

func (e PilosaError) Error() string {
return fmt.Sprintf("PilosaError: %s", e.Message)
func (e Error) Error() string {
return fmt.Sprintf("Error: %s", e.Message)
}

//
var (
ErrorEmptyCluster = NewPilosaError("No usable addresses in the cluster")
ErrorIndexExists = NewPilosaError("Index exists")
ErrorFrameExists = NewPilosaError("Frame exists")
ErrorInvalidIndexName = NewPilosaError("Invalid index name")
ErrorInvalidFrameName = NewPilosaError("Invalid frame name")
ErrorInvalidLabel = NewPilosaError("Invalid label")
ErrorInverseBitmapsNotEnabled = NewPilosaError("Inverse bitmaps support was not enabled for this frame")
ErrorEmptyCluster = NewError("No usable addresses in the cluster")
ErrorIndexExists = NewError("Index exists")
ErrorFrameExists = NewError("Frame exists")
ErrorInvalidIndexName = NewError("Invalid index name")
ErrorInvalidFrameName = NewError("Invalid frame name")
ErrorInvalidLabel = NewError("Invalid label")
ErrorInverseBitmapsNotEnabled = NewError("Inverse bitmaps support was not enabled for this frame")
)
4 changes: 2 additions & 2 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import (
)

func TestError(t *testing.T) {
err := NewPilosaError("some error")
if err.Error() != "PilosaError: some error" {
err := NewError("some error")
if err.Error() != "Error: some error" {
fmt.Println(err.Error())
t.Fatal()
}
Expand Down
1 change: 1 addition & 0 deletions orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (q PQLBitmapQuery) Error() error {
return q.err
}

// PQLBatchQuery contains several queries to increase throughput
type PQLBatchQuery struct {
index *Index
queries []string
Expand Down
1 change: 1 addition & 0 deletions uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (u *URI) Normalize() string {
return fmt.Sprintf("%s://%s:%d", scheme, u.host, u.port)
}

// Equals returns true if the checked URI is equivalent to this URI
func (u URI) Equals(other *URI) bool {
if other == nil {
return false
Expand Down

0 comments on commit b27da62

Please sign in to comment.