0
0
Fork 0

changed error constants to camel case

all caps constants are not idiomatic go
This commit is contained in:
Marty Schoch 2014-09-02 14:14:05 -04:00
parent f6a3831687
commit bbc6fadf69
10 changed files with 51 additions and 51 deletions

View File

@ -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
@ -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",
}

View File

@ -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
@ -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)
@ -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{}{
@ -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)
@ -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)
@ -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))
@ -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)
}
@ -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)
@ -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()
}

View File

@ -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
}
@ -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 {
@ -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
}

View File

@ -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)
}
}
@ -374,7 +374,7 @@ 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)
}
@ -382,7 +382,7 @@ func TestIndexOpenMetaMissingOrCorrupt(t *testing.T) {
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)
}
}

View File

@ -176,5 +176,5 @@ func ParseQuery(input []byte) (Query, error) {
}
return &rv, nil
}
return nil, ERROR_UNKNOWN_QUERY_TYPE
return nil, ErrorUnknownQueryType
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -67,7 +67,7 @@ func TestParseQuery(t *testing.T) {
{
input: []byte(`{"madeitup":"queryhere"}`),
output: nil,
err: ERROR_UNKNOWN_QUERY_TYPE,
err: ErrorUnknownQueryType,
},
}
@ -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"),
@ -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),
@ -192,14 +192,14 @@ 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(
@ -207,7 +207,7 @@ func TestQueryValidate(t *testing.T) {
[]Query{NewMatchQuery("water").SetField("desc")},
[]Query{NewMatchQuery("devon").SetField("desc")},
2.0),
err: ERROR_DISJUNCTION_FEWER_THAN_MIN_CLAUSES,
err: ErrorDisjunctionFewerThanMinClauses,
},
}