Skip to content

Commit

Permalink
changed error constants to camel case
Browse files Browse the repository at this point in the history
all caps constants are not idiomatic go
  • Loading branch information
mschoch committed Sep 2, 2014
1 parent f6a3831 commit bbc6fad
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 51 deletions.
44 changes: 22 additions & 22 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
package bleve

const (
ERROR_INDEX_PATH_EXISTS Error = iota
ERROR_INDEX_PATH_DOES_NOT_EXIST
ERROR_INDEX_META_MISSING
ERROR_INDEX_META_CORRUPT
ERROR_DISJUNCTION_FEWER_THAN_MIN_CLAUSES
ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD
ERROR_NUMERIC_QUERY_NO_BOUNDS
ERROR_PHRASE_QUERY_NO_TERMS
ERROR_UNKNOWN_QUERY_TYPE
ERROR_UNKNOWN_STORAGE_TYPE
ERROR_INDEX_CLOSED
ErrorIndexPathExists Error = iota
ErrorIndexPathDoesNotExist
ErrorIndexMetaMissing
ErrorIndexMetaCorrupt
ErrorDisjunctionFewerThanMinClauses
ErrorBooleanQueryNeedsMustOrShould
ErrorNumericQueryNoBounds
ErrorPhraseQueryNoTerms
ErrorUnknownQueryType
ErrorUnknownStorageType
ErrorIndexClosed
)

type Error int
Expand All @@ -30,15 +30,15 @@ func (e Error) Error() string {
}

var errorMessages = map[int]string{
int(ERROR_INDEX_PATH_EXISTS): "cannot create new index, path already exists",
int(ERROR_INDEX_PATH_DOES_NOT_EXIST): "cannot open index, path does not exist",
int(ERROR_INDEX_META_MISSING): "cannot open index, metadata missing",
int(ERROR_INDEX_META_CORRUPT): "cannot open index, metadata corrupt",
int(ERROR_DISJUNCTION_FEWER_THAN_MIN_CLAUSES): "disjunction query has fewer than the minimum number of clauses to satisfy",
int(ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD): "boolean query must contain at least one must or should clause",
int(ERROR_NUMERIC_QUERY_NO_BOUNDS): "numeric range query must specify min or max",
int(ERROR_PHRASE_QUERY_NO_TERMS): "phrase query must contain at least one term",
int(ERROR_UNKNOWN_QUERY_TYPE): "unknown query type",
int(ERROR_UNKNOWN_STORAGE_TYPE): "unkown storage type",
int(ERROR_INDEX_CLOSED): "index is closed",
int(ErrorIndexPathExists): "cannot create new index, path already exists",
int(ErrorIndexPathDoesNotExist): "cannot open index, path does not exist",
int(ErrorIndexMetaMissing): "cannot open index, metadata missing",
int(ErrorIndexMetaCorrupt): "cannot open index, metadata corrupt",
int(ErrorDisjunctionFewerThanMinClauses): "disjunction query has fewer than the minimum number of clauses to satisfy",
int(ErrorBooleanQueryNeedsMustOrShould): "boolean query must contain at least one must or should clause",
int(ErrorNumericQueryNoBounds): "numeric range query must specify min or max",
int(ErrorPhraseQueryNoTerms): "phrase query must contain at least one term",
int(ErrorUnknownQueryType): "unknown query type",
int(ErrorUnknownStorageType): "unkown storage type",
int(ErrorIndexClosed): "index is closed",
}
18 changes: 9 additions & 9 deletions index_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newMemIndex(mapping *IndexMapping) (*indexImpl, error) {

storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
if storeConstructor == nil {
return nil, ERROR_UNKNOWN_STORAGE_TYPE
return nil, ErrorUnknownStorageType
}
// now open the store
var err error
Expand Down Expand Up @@ -104,7 +104,7 @@ func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
}
storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
if storeConstructor == nil {
return nil, ERROR_UNKNOWN_STORAGE_TYPE
return nil, ErrorUnknownStorageType
}
// at this point there hope we can be successful, so save index meta
err = rv.meta.Save(path)
Expand Down Expand Up @@ -160,7 +160,7 @@ func openIndex(path string) (*indexImpl, error) {

storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
if storeConstructor == nil {
return nil, ERROR_UNKNOWN_STORAGE_TYPE
return nil, ErrorUnknownStorageType
}

storeConfig := map[string]interface{}{
Expand Down Expand Up @@ -225,7 +225,7 @@ func (i *indexImpl) Index(id string, data interface{}) error {
defer i.mutex.Unlock()

if !i.open {
return ERROR_INDEX_CLOSED
return ErrorIndexClosed
}

doc := document.NewDocument(id)
Expand All @@ -247,7 +247,7 @@ func (i *indexImpl) Delete(id string) error {
defer i.mutex.Unlock()

if !i.open {
return ERROR_INDEX_CLOSED
return ErrorIndexClosed
}

err := i.i.Delete(id)
Expand All @@ -266,7 +266,7 @@ func (i *indexImpl) Batch(b Batch) error {
defer i.mutex.Unlock()

if !i.open {
return ERROR_INDEX_CLOSED
return ErrorIndexClosed
}

ib := make(index.Batch, len(b))
Expand Down Expand Up @@ -294,7 +294,7 @@ func (i *indexImpl) Document(id string) (*document.Document, error) {
defer i.mutex.RUnlock()

if !i.open {
return nil, ERROR_INDEX_CLOSED
return nil, ErrorIndexClosed
}
return i.i.Document(id)
}
Expand All @@ -319,7 +319,7 @@ func (i *indexImpl) Search(req *SearchRequest) (*SearchResult, error) {
defer i.mutex.RUnlock()

if !i.open {
return nil, ERROR_INDEX_CLOSED
return nil, ErrorIndexClosed
}

collector := collectors.NewTopScorerSkipCollector(req.Size, req.From)
Expand Down Expand Up @@ -450,7 +450,7 @@ func (i *indexImpl) Fields() ([]string, error) {
defer i.mutex.RUnlock()

if !i.open {
return nil, ERROR_INDEX_CLOSED
return nil, ErrorIndexClosed
}
return i.i.Fields()
}
Expand Down
10 changes: 5 additions & 5 deletions index_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ func newIndexMeta(storage string) *indexMeta {

func openIndexMeta(path string) (*indexMeta, error) {
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, ERROR_INDEX_PATH_DOES_NOT_EXIST
return nil, ErrorIndexPathDoesNotExist
}
indexMetaPath := indexMetaPath(path)
metaBytes, err := ioutil.ReadFile(indexMetaPath)
if err != nil {
return nil, ERROR_INDEX_META_MISSING
return nil, ErrorIndexMetaMissing
}
var im indexMeta
err = json.Unmarshal(metaBytes, &im)
if err != nil {
return nil, ERROR_INDEX_META_CORRUPT
return nil, ErrorIndexMetaCorrupt
}
return &im, nil
}
Expand All @@ -47,7 +47,7 @@ func (i *indexMeta) Save(path string) error {
// ensure any necessary parent directories exist
err := os.Mkdir(path, 0700)
if err != nil {
return ERROR_INDEX_PATH_EXISTS
return ErrorIndexPathExists
}
metaBytes, err := json.Marshal(i)
if err != nil {
Expand All @@ -56,7 +56,7 @@ func (i *indexMeta) Save(path string) error {
indexMetaFile, err := os.OpenFile(indexMetaPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
if err != nil {
if os.IsExist(err) {
return ERROR_INDEX_PATH_EXISTS
return ErrorIndexPathExists
} else {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,14 @@ func TestIndexCreateNewOverExisting(t *testing.T) {
}
index.Close()
index, err = New("testidx", NewIndexMapping())
if err != ERROR_INDEX_PATH_EXISTS {
if err != ErrorIndexPathExists {
t.Fatalf("expected error index path exists, got %v", err)
}
}

func TestIndexOpenNonExisting(t *testing.T) {
_, err := Open("doesnotexist")
if err != ERROR_INDEX_PATH_DOES_NOT_EXIST {
if err != ErrorIndexPathDoesNotExist {
t.Fatalf("expected error index path does not exist, got %v", err)
}
}
Expand All @@ -374,15 +374,15 @@ func TestIndexOpenMetaMissingOrCorrupt(t *testing.T) {
ioutil.WriteFile("testidx/index_meta.json", []byte("corrupted"), 0666)

index, err = Open("testidx")
if err != ERROR_INDEX_META_CORRUPT {
if err != ErrorIndexMetaCorrupt {
t.Fatalf("expected error index metadata corrupted, got %v", err)
}

// no intentionally remove the metadata
os.Remove("testidx/index_meta.json")

index, err = Open("testidx")
if err != ERROR_INDEX_META_MISSING {
if err != ErrorIndexMetaMissing {
t.Fatalf("expected error index metadata missing, got %v", err)
}
}
2 changes: 1 addition & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ func ParseQuery(input []byte) (Query, error) {
}
return &rv, nil
}
return nil, ERROR_UNKNOWN_QUERY_TYPE
return nil, ErrorUnknownQueryType
}
2 changes: 1 addition & 1 deletion query_boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (q *booleanQuery) Validate() error {
}
}
if q.Must == nil && q.Should == nil {
return ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD
return ErrorBooleanQueryNeedsMustOrShould
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion query_disjunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (q *disjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher

func (q *disjunctionQuery) Validate() error {
if int(q.MinVal) > len(q.Disjuncts) {
return ERROR_DISJUNCTION_FEWER_THAN_MIN_CLAUSES
return ErrorDisjunctionFewerThanMinClauses
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion query_numeric_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (q *numericRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searche

func (q *numericRangeQuery) Validate() error {
if q.Min == nil && q.Min == q.Max {
return ERROR_NUMERIC_QUERY_NO_BOUNDS
return ErrorNumericQueryNoBounds
}
return nil
}
2 changes: 1 addition & 1 deletion query_phrase.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (q *phraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, err

func (q *phraseQuery) Validate() error {
if len(q.Terms) < 1 {
return ERROR_PHRASE_QUERY_NO_TERMS
return ErrorPhraseQueryNoTerms
}
return nil
}
Expand Down
12 changes: 6 additions & 6 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestParseQuery(t *testing.T) {
{
input: []byte(`{"madeitup":"queryhere"}`),
output: nil,
err: ERROR_UNKNOWN_QUERY_TYPE,
err: ErrorUnknownQueryType,
},
}

Expand Down Expand Up @@ -150,7 +150,7 @@ func TestQueryValidate(t *testing.T) {
},
{
query: NewNumericRangeQuery(nil, nil).SetField("desc"),
err: ERROR_NUMERIC_QUERY_NO_BOUNDS,
err: ErrorNumericQueryNoBounds,
},
{
query: NewDateRangeQuery(&startDate, &endDate).SetField("desc"),
Expand All @@ -170,7 +170,7 @@ func TestQueryValidate(t *testing.T) {
},
{
query: NewPhraseQuery([]string{}, "field"),
err: ERROR_PHRASE_QUERY_NO_TERMS,
err: ErrorPhraseQueryNoTerms,
},
{
query: NewMatchNoneQuery().SetBoost(25),
Expand All @@ -192,22 +192,22 @@ func TestQueryValidate(t *testing.T) {
nil,
nil,
[]Query{NewMatchQuery("devon").SetField("desc")}),
err: ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD,
err: ErrorBooleanQueryNeedsMustOrShould,
},
{
query: NewBooleanQuery(
[]Query{},
[]Query{},
[]Query{NewMatchQuery("devon").SetField("desc")}),
err: ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD,
err: ErrorBooleanQueryNeedsMustOrShould,
},
{
query: NewBooleanQueryMinShould(
[]Query{NewMatchQuery("beer").SetField("desc")},
[]Query{NewMatchQuery("water").SetField("desc")},
[]Query{NewMatchQuery("devon").SetField("desc")},
2.0),
err: ERROR_DISJUNCTION_FEWER_THAN_MIN_CLAUSES,
err: ErrorDisjunctionFewerThanMinClauses,
},
}

Expand Down

0 comments on commit bbc6fad

Please sign in to comment.