Susumu Yata
null+****@clear*****
Tue Jul 11 11:02:23 JST 2017
Susumu Yata 2017-07-11 11:02:23 +0900 (Tue, 11 Jul 2017) New Revision: 22008ca90899574284a34457defd20cd694b469f https://github.com/groonga/grnci/commit/22008ca90899574284a34457defd20cd694b469f Message: Rename error codes from Invalid* to *Error. Modified files: v2/address.go v2/command.go v2/db.go v2/error.go v2/error_test.go v2/gqtp.go v2/http.go v2/libgrn/conn.go v2/libgrn/libgrn.go v2/type.go Modified: v2/address.go (+11 -11) =================================================================== --- v2/address.go 2017-07-11 10:49:59 +0900 (1240bad) +++ v2/address.go 2017-07-11 11:02:23 +0900 (00d26a9) @@ -40,13 +40,13 @@ func (a *Address) fillGQTP() error { a.Scheme = "gqtp" } if a.Username != "" { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "username": a.Username, "error": "GQTP does not accept username.", }) } if a.Password != "" { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "password": a.Password, "error": "GQTP does not accept password.", }) @@ -58,19 +58,19 @@ func (a *Address) fillGQTP() error { a.Port = DefaultGQTPPort } if a.Path != "" { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "path": a.Path, "error": "GQTP does not accept path.", }) } if a.Query != "" { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "query": a.Query, "error": "GQTP does not accept query.", }) } if a.Fragment != "" { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "fragment": a.Fragment, "error": "GQTP does not accept fragment.", }) @@ -110,7 +110,7 @@ func (a *Address) fill() error { return err } default: - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "scheme": a.Scheme, "error": "The scheme is not supported.", }) @@ -127,7 +127,7 @@ func (a *Address) parseHostPort(s string) error { if s[0] == '[' { i := strings.IndexByte(s, ']') if i == -1 { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "address": s, "error": "IPv6 address must be enclosed in [].", }) @@ -138,7 +138,7 @@ func (a *Address) parseHostPort(s string) error { return nil } if rest[0] != ':' { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "address": s, "error": "IPv6 address and port must be separated by ':'.", }) @@ -156,7 +156,7 @@ func (a *Address) parseHostPort(s string) error { if portStr != "" { port, err := net.LookupPort("tcp", portStr) if err != nil { - return NewError(InvalidAddress, map[string]interface{}{ + return NewError(AddressError, map[string]interface{}{ "port": portStr, "error": err.Error(), }) @@ -239,7 +239,7 @@ func ParseGQTPAddress(s string) (*Address, error) { switch strings.ToLower(a.Scheme) { case "", "gqtp": default: - return nil, NewError(InvalidAddress, map[string]interface{}{ + return nil, NewError(AddressError, map[string]interface{}{ "scheme": a.Scheme, "error": "The scheme is not supported.", }) @@ -266,7 +266,7 @@ func ParseHTTPAddress(s string) (*Address, error) { switch strings.ToLower(a.Scheme) { case "", "http", "https": default: - return nil, NewError(InvalidAddress, map[string]interface{}{ + return nil, NewError(AddressError, map[string]interface{}{ "scheme": a.Scheme, "error": "The scheme is not supported.", }) Modified: v2/command.go (+18 -18) =================================================================== --- v2/command.go 2017-07-11 10:49:59 +0900 (34a86ba) +++ v2/command.go 2017-07-11 11:02:23 +0900 (61ae0bb) @@ -32,7 +32,7 @@ func formatParamValue(key string, value interface{}) (string, error) { case reflect.String: return v.String(), nil default: - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "value": value, "type": reflect.TypeOf(value).Name(), @@ -54,14 +54,14 @@ func formatParamBoolean(key string, value interface{}, t, f string) (string, err case t, f: return v, nil default: - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "value": v, "error": fmt.Sprintf("The value must be %s or %s.", t, f), }) } default: - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "value": value, "type": reflect.TypeOf(value).Name(), @@ -99,7 +99,7 @@ func formatParamDelim(key string, value interface{}, delim string) (string, erro } return string(buf), nil } - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "value": value, "type": reflect.TypeOf(value).Name(), @@ -156,7 +156,7 @@ type formatParam func(key string, value interface{}) (string, error) // formatParamDefault is the default formatParam. func formatParamDefault(key string, value interface{}) (string, error) { if key == "" { - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "error": "The key must not be empty.", }) @@ -166,7 +166,7 @@ func formatParamDefault(key string, value interface{}) (string, error) { case c >= 'a' && c <= 'z': case c == '_': default: - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "error": "The key must consist of [a-z_].", }) @@ -178,7 +178,7 @@ func formatParamDefault(key string, value interface{}) (string, error) { // formatParamSelect formats a parameter of select. func formatParamSelect(key string, value interface{}) (string, error) { if key == "" { - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "error": "The key must not be empty.", }) @@ -192,7 +192,7 @@ func formatParamSelect(key string, value interface{}) (string, error) { switch c { case '#', '@', '-', '_', '.', '[', ']': default: - return "", NewError(InvalidCommand, map[string]interface{}{ + return "", NewError(CommandError, map[string]interface{}{ "key": key, "error": "The key must consist of [0-9A-Za-z#@-_.[]].", }) @@ -622,7 +622,7 @@ type Command struct { func newCommand(name string) (*Command, error) { format := getCommandFormat(name) if format == nil { - return nil, NewError(InvalidCommand, map[string]interface{}{ + return nil, NewError(CommandError, map[string]interface{}{ "name": name, "error": "The name is not defined.", }) @@ -689,7 +689,7 @@ func tokenizeCommand(cmd string) ([]string, error) { } i++ if i == len(s) { - return nil, NewError(InvalidCommand, map[string]interface{}{ + return nil, NewError(CommandError, map[string]interface{}{ "command": cmd, "error": "The command ends with an unclosed token.", }) @@ -707,7 +707,7 @@ func tokenizeCommand(cmd string) ([]string, error) { case '\\': i++ if i == len(s) { - return nil, NewError(InvalidCommand, map[string]interface{}{ + return nil, NewError(CommandError, map[string]interface{}{ "command": cmd, "error": "The command ends with an escape character.", }) @@ -740,7 +740,7 @@ func ParseCommand(cmd string) (*Command, error) { return nil, err } if len(tokens) == 0 { - return nil, NewError(InvalidCommand, map[string]interface{}{ + return nil, NewError(CommandError, map[string]interface{}{ "command": cmd, "error": "The command has no tokens.", }) @@ -757,7 +757,7 @@ func ParseCommand(cmd string) (*Command, error) { k = tokens[i][2:] i++ if i >= len(tokens) { - return nil, NewError(InvalidCommand, map[string]interface{}{ + return nil, NewError(CommandError, map[string]interface{}{ "command": cmd, "key": k, "error": "The key requires a value.", @@ -801,7 +801,7 @@ func (c *Command) NeedsBody() bool { func (c *Command) Check() error { for _, pf := range c.format.requiredParams { if _, ok := c.params[pf.key]; !ok { - return NewError(InvalidCommand, map[string]interface{}{ + return NewError(CommandError, map[string]interface{}{ "name": c.name, "key": pf.key, "error": "The command requires the key.", @@ -810,7 +810,7 @@ func (c *Command) Check() error { } if c.NeedsBody() { if c.body == nil { - return NewError(InvalidCommand, map[string]interface{}{ + return NewError(CommandError, map[string]interface{}{ "name": c.name, "error": "The command requires a body", }) @@ -825,7 +825,7 @@ func (c *Command) Check() error { func (c *Command) SetParam(key string, value interface{}) error { if value == nil { if _, ok := c.params[key]; !ok { - return NewError(InvalidCommand, map[string]interface{}{ + return NewError(CommandError, map[string]interface{}{ "name": c.name, "key": key, "error": "The key does not exist.", @@ -836,7 +836,7 @@ func (c *Command) SetParam(key string, value interface{}) error { } if key == "" { if c.index >= len(c.format.params) { - return NewError(InvalidCommand, map[string]interface{}{ + return NewError(CommandError, map[string]interface{}{ "name": c.name, "index": c.index, "error": "The index is too large.", @@ -1038,7 +1038,7 @@ func (cr *CommandReader) fill() error { if err != nil { cr.err = err if err != io.EOF { - cr.err = NewError(InvalidCommand, map[string]interface{}{ + cr.err = NewError(CommandError, map[string]interface{}{ "error": err.Error(), }) } Modified: v2/db.go (+75 -75) =================================================================== --- v2/db.go 2017-07-11 10:49:59 +0900 (dd72603) +++ v2/db.go 2017-07-11 11:02:23 +0900 (a261e84) @@ -33,7 +33,7 @@ func (db *DB) recvBool(resp Response) (bool, Response, error) { if resp.Err() != nil { return false, resp, nil } - return false, resp, NewError(InvalidResponse, map[string]interface{}{ + return false, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -53,7 +53,7 @@ func (db *DB) recvInt(resp Response) (int, Response, error) { if resp.Err() != nil { return 0, resp, nil } - return 0, resp, NewError(InvalidResponse, map[string]interface{}{ + return 0, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -73,7 +73,7 @@ func (db *DB) recvString(resp Response) (string, Response, error) { if resp.Err() != nil { return "", resp, nil } - return "", resp, NewError(InvalidResponse, map[string]interface{}{ + return "", resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -101,7 +101,7 @@ func (db *DB) CacheLimit(max int) (int, Response, error) { func (db *DB) ColumnCopy(from, to string) (bool, Response, error) { i := strings.IndexByte(from, '.') if i == -1 { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "from": from, "error": "The from must contain a dot.", }) @@ -109,7 +109,7 @@ func (db *DB) ColumnCopy(from, to string) (bool, Response, error) { fromTable := from[:i] fromName := from[i+1:] if i = strings.IndexByte(to, '.'); i == -1 { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "to": to, "error": "The to must contain a dot.", }) @@ -132,7 +132,7 @@ func (db *DB) ColumnCopy(from, to string) (bool, Response, error) { func (db *DB) ColumnCreate(name, typ string, flags []string) (bool, Response, error) { i := strings.IndexByte(name, '.') if i == -1 { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "name": name, "error": "The name must contain a dot.", }) @@ -197,13 +197,13 @@ func (db *DB) ColumnList(tbl string) ([]DBColumn, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } if len(result) == 0 { - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "error": "The result is empty.", }) } @@ -267,7 +267,7 @@ func (db *DB) ColumnList(tbl string) ([]DBColumn, Response, error) { func (db *DB) ColumnRemove(name string) (bool, Response, error) { i := strings.IndexByte(name, '.') if i == -1 { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "name": name, "error": "The name must contain a dot.", }) @@ -286,14 +286,14 @@ func (db *DB) ColumnRemove(name string) (bool, Response, error) { func (db *DB) ColumnRename(name, newName string) (bool, Response, error) { i := strings.IndexByte(name, '.') if i == -1 { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "name": name, "error": "The name must contain a dot.", }) } if j := strings.IndexByte(newName, '.'); j != -1 { if i != j || name[:i] != newName[:i] { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "name": name, "newName": newName, "error": "The names have different table names.", @@ -545,7 +545,7 @@ func (db *DB) LoadRows(tbl string, rows interface{}, options *DBLoadOptions) (in for _, col := range options.Columns { cf, ok := rs.ColumnsByName[col] if !ok { - return 0, nil, NewError(InvalidCommand, map[string]interface{}{ + return 0, nil, NewError(CommandError, map[string]interface{}{ "column": col, "error": "The column has no associated field.", }) @@ -559,14 +559,14 @@ func (db *DB) LoadRows(tbl string, rows interface{}, options *DBLoadOptions) (in switch v.Kind() { case reflect.Ptr: if v.IsNil() { - return 0, nil, NewError(InvalidCommand, map[string]interface{}{ + return 0, nil, NewError(CommandError, map[string]interface{}{ "rows": nil, "error": "The rows must not be nil.", }) } v = v.Elem() if v.Kind() != reflect.Struct { - return 0, nil, NewError(InvalidCommand, map[string]interface{}{ + return 0, nil, NewError(CommandError, map[string]interface{}{ "type": reflect.TypeOf(rows).Name(), "error": "The type is not supported.", }) @@ -577,7 +577,7 @@ func (db *DB) LoadRows(tbl string, rows interface{}, options *DBLoadOptions) (in case reflect.Struct: body = db.appendRow(body, v, cfs) default: - return 0, nil, NewError(InvalidCommand, map[string]interface{}{ + return 0, nil, NewError(CommandError, map[string]interface{}{ "type": reflect.TypeOf(rows).Name(), "error": "The type is not supported.", }) @@ -734,7 +734,7 @@ func (db *DB) LogicalParameters(rangeIndex string) (*DBLogicalParameters, Respon if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -872,7 +872,7 @@ func (db *DB) LogicalSelectRows(logicalTable, shardKey string, rows interface{}, for _, col := range options.OutputColumns { cf, ok := rs.ColumnsByName[col] if !ok { - return 0, nil, NewError(InvalidCommand, map[string]interface{}{ + return 0, nil, NewError(CommandError, map[string]interface{}{ "column": col, "error": "The column has no associated field.", }) @@ -919,7 +919,7 @@ func (db *DB) LogicalShardList(logicalTable string) ([]DBLogicalShard, Response, if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1001,7 +1001,7 @@ func (db *DB) Normalize(normalizer, str string, flags []string) (*DBNormalizedTe if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1030,7 +1030,7 @@ func (db *DB) NormalizerList() ([]DBNormalizer, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1165,7 +1165,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1177,7 +1177,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1193,7 +1193,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1205,7 +1205,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1217,7 +1217,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1227,7 +1227,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "command": "object_inspect", "error": "The response format is not invalid.", }) @@ -1274,7 +1274,7 @@ func (db *DB) ObjectList() (map[string]*DBObject, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1406,7 +1406,7 @@ func (db *DB) RequestCancel(id int) (bool, Response, error) { if resp.Err() != nil { return false, resp, nil } - return false, resp, NewError(InvalidResponse, map[string]interface{}{ + return false, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1435,7 +1435,7 @@ func (db *DB) RubyEval(script string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return false, resp, NewError(InvalidResponse, map[string]interface{}{ + return false, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1464,7 +1464,7 @@ func (db *DB) RubyLoad(path string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return false, resp, NewError(InvalidResponse, map[string]interface{}{ + return false, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1590,7 +1590,7 @@ func (db *DB) Schema() (*DBSchema, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1805,7 +1805,7 @@ func (db *DB) Select(tbl string, options *DBSelectOptions) (io.ReadCloser, Respo func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, error) { var raw [][][]json.RawMessage if err := json.Unmarshal(data, &raw); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1826,7 +1826,7 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, for _, rawCol := range rawCols { var nameType []string if err := json.Unmarshal(rawCol, &nameType); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1846,7 +1846,7 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, } } if nCols != len(cfs) { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "nFields": len(cfs), "nCols": nCols, "error": "nFields and nColumns must be same.", @@ -1877,98 +1877,98 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, switch v := ptr.Interface().(type) { case *bool: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *int: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *int8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *int16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *int32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *int64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *uint: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *uint8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *uint16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *uint32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *uint64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *float32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *float64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *string: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1976,7 +1976,7 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, case *time.Time: var f float64 if err := json.Unmarshal(rawRecs[i][j], &f); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -1984,98 +1984,98 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, *v = time.Unix(int64(f), int64(f*1000000)%1000000) case *[]bool: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]int: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]int8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]int16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]int32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]int64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]uint: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]uint8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]uint16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]uint32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]uint64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]float32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]float64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } case *[]string: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -2083,7 +2083,7 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, case *[]time.Time: var f []float64 if err := json.Unmarshal(rawRecs[i][j], &f); err != nil { - return 0, NewError(InvalidResponse, map[string]interface{}{ + return 0, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -2118,7 +2118,7 @@ func (db *DB) SelectRows(tbl string, rows interface{}, options *DBSelectOptions) for _, col := range options.OutputColumns { cf, ok := rs.ColumnsByName[col] if !ok { - return 0, nil, NewError(InvalidCommand, map[string]interface{}{ + return 0, nil, NewError(CommandError, map[string]interface{}{ "column": col, "error": "The column has no associated field.", }) @@ -2186,7 +2186,7 @@ func (db *DB) Status() (*DBStatus, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -2283,13 +2283,13 @@ func (db *DB) TableCreate(name string, options *DBTableCreateOptions) (bool, Res switch flag { case "TABLE_NO_KEY": if keyFlag != "" { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "flags": flags, "error": "The combination of flags is wrong.", }) } if options.KeyType != "" { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "flags": flags, "key_type": options.KeyType, "error": "TABLE_NO_KEY denies key_type.", @@ -2298,13 +2298,13 @@ func (db *DB) TableCreate(name string, options *DBTableCreateOptions) (bool, Res keyFlag = flag case "TABLE_HASH_KEY", "TABLE_PAT_KEY", "TABLE_DAT_KEY": if keyFlag != "" { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "flags": flags, "error": "The combination of flags is wrong.", }) } if options.KeyType == "" { - return false, nil, NewError(InvalidCommand, map[string]interface{}{ + return false, nil, NewError(CommandError, map[string]interface{}{ "flags": flags, "key_type": options.KeyType, "error": fmt.Sprintf("%s requires key_type.", flag), @@ -2375,13 +2375,13 @@ func (db *DB) TableList() ([]DBTable, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } if len(result) == 0 { - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "error": "The result is empty.", }) } @@ -2512,7 +2512,7 @@ func (db *DB) TableTokenize(tbl, str string, options *DBTableTokenizeOptions) ([ if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -2584,7 +2584,7 @@ func (db *DB) Tokenize(tokenizer, str string, options *DBTokenizeOptions) ([]DBT if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) @@ -2613,7 +2613,7 @@ func (db *DB) TokenizerList() ([]DBTokenizer, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(InvalidResponse, map[string]interface{}{ + return nil, resp, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) Modified: v2/error.go (+19 -19) =================================================================== --- v2/error.go 2017-07-11 10:49:59 +0900 (f808b46) +++ v2/error.go 2017-07-11 11:02:23 +0900 (14a3550) @@ -6,11 +6,11 @@ import ( // Error codes. const ( - InvalidAddress = 1000 + iota - InvalidCommand - InvalidOperation - InvalidResponse - InvalidType + AddressError = 1000 + iota + CommandError + OperationError + ResponseError + TypeError NetworkError HTTPError UnknownError @@ -184,25 +184,25 @@ func getCodeText(code int) string { case -79: return "GRN_ZSTD_ERROR" - case InvalidAddress: - return "invalid address" - case InvalidCommand: - return "invalid command" - case InvalidOperation: - return "invalid operation" - case InvalidResponse: - return "invalid response" - case InvalidType: - return "invalid type" + case AddressError: + return "AddressError" + case CommandError: + return "CommandError" + case OperationError: + return "OperationError" + case ResponseError: + return "ResponseError" + case TypeError: + return "TypeError" case NetworkError: - return "network error" + return "NetworkError" case HTTPError: - return "HTTP error" + return "HTTPError" case UnknownError: - return "unknown error" + return "UnknownError" default: - return "undefined error" + return "N/A" } } Modified: v2/error_test.go (+10 -10) =================================================================== --- v2/error_test.go 2017-07-11 10:49:59 +0900 (8cc4292) +++ v2/error_test.go 2017-07-11 11:02:23 +0900 (785393b) @@ -7,14 +7,14 @@ func TestNewError(t *testing.T) { "string": "value", "int": 100, } - err := NewError(InvalidAddress, data) - if err.Code != InvalidAddress { + err := NewError(AddressError, data) + if err.Code != AddressError { t.Fatalf("NewError failed: Code: actual = %d, want = %d", - err.Code, InvalidAddress) + err.Code, AddressError) } - if err.Text != getCodeText(InvalidAddress) { + if err.Text != getCodeText(AddressError) { t.Fatalf("NewError failed: Text: actual = %s, want = %s", - err.Text, getCodeText(InvalidAddress)) + err.Text, getCodeText(AddressError)) } for k, v := range data { if err.Data[k] != v { @@ -33,15 +33,15 @@ func TestEnhanceError(t *testing.T) { "int": 1000, "float": 1.0, } - err := NewError(InvalidAddress, data) + err := NewError(AddressError, data) err = EnhanceError(err, newData) - if err.Code != InvalidAddress { + if err.Code != AddressError { t.Fatalf("NewError failed: Code: actual = %d, want = %d", - err.Code, InvalidAddress) + err.Code, AddressError) } - if err.Text != getCodeText(InvalidAddress) { + if err.Text != getCodeText(AddressError) { t.Fatalf("NewError failed: Text: actual = %s, want = %s", - err.Text, getCodeText(InvalidAddress)) + err.Text, getCodeText(AddressError)) } for k, v := range newData { if err.Data[k] != v { Modified: v2/gqtp.go (+2 -2) =================================================================== --- v2/gqtp.go 2017-07-11 10:49:59 +0900 (8ad8413) +++ v2/gqtp.go 2017-07-11 11:02:23 +0900 (ae1dc65) @@ -342,12 +342,12 @@ func (c *GQTPConn) execBody(cmd string, body io.Reader) (Response, error) { // exec sends a command without body and receives a response. func (c *GQTPConn) exec(cmd string, body io.Reader) (Response, error) { if !c.ready { - return nil, NewError(InvalidOperation, map[string]interface{}{ + return nil, NewError(OperationError, map[string]interface{}{ "error": "The connection is not ready to send a command.", }) } if len(cmd) > gqtpMaxChunkSize { - return nil, NewError(InvalidCommand, map[string]interface{}{ + return nil, NewError(CommandError, map[string]interface{}{ "length": len(cmd), "error": "The command is too long.", }) Modified: v2/http.go (+9 -9) =================================================================== --- v2/http.go 2017-07-11 10:49:59 +0900 (76afad4) +++ v2/http.go 2017-07-11 11:02:23 +0900 (f73c617) @@ -32,7 +32,7 @@ type httpResponse struct { func extractHTTPResponseHeader(data []byte) (head, left []byte, err error) { left = bytes.TrimLeft(data[1:], " \t\r\n") if !bytes.HasPrefix(left, []byte("[")) { - err = NewError(InvalidResponse, map[string]interface{}{ + err = NewError(ResponseError, map[string]interface{}{ "error": "The response does not contain a header.", }) return @@ -48,7 +48,7 @@ Loop: stack = append(stack, '}') case ']', '}': if left[i] != stack[len(stack)-1] { - err = NewError(InvalidResponse, map[string]interface{}{ + err = NewError(ResponseError, map[string]interface{}{ "error": "The response header is broken.", }) return @@ -70,7 +70,7 @@ Loop: } } if len(stack) != 0 { - err = NewError(InvalidResponse, map[string]interface{}{ + err = NewError(ResponseError, map[string]interface{}{ "error": "The response header is too long or broken.", }) return @@ -132,20 +132,20 @@ func parseHTTPResponseHeader(resp *http.Response, data []byte) (*httpResponse, e var elems []interface{} if err := json.Unmarshal(head, &elems); err != nil { - return nil, NewError(InvalidResponse, map[string]interface{}{ + return nil, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": err.Error(), }) } if len(elems) < 3 { - return nil, NewError(InvalidResponse, map[string]interface{}{ + return nil, NewError(ResponseError, map[string]interface{}{ "method": "json.Unmarshal", "error": "Too few elements in the response header.", }) } f, ok := elems[0].(float64) if !ok { - return nil, NewError(InvalidResponse, map[string]interface{}{ + return nil, NewError(ResponseError, map[string]interface{}{ "code": elems[0], "error": "code must be a number.", }) @@ -153,7 +153,7 @@ func parseHTTPResponseHeader(resp *http.Response, data []byte) (*httpResponse, e code := int(f) f, ok = elems[1].(float64) if !ok { - return nil, NewError(InvalidResponse, map[string]interface{}{ + return nil, NewError(ResponseError, map[string]interface{}{ "start": elems[1], "error": "start must be a number.", }) @@ -162,7 +162,7 @@ func parseHTTPResponseHeader(resp *http.Response, data []byte) (*httpResponse, e start := time.Unix(int64(i), int64(math.Floor(f*1000000+0.5))*1000).Local() f, ok = elems[2].(float64) if !ok { - return nil, NewError(InvalidResponse, map[string]interface{}{ + return nil, NewError(ResponseError, map[string]interface{}{ "elapsed": elems[2], "error": "elapsed must be a number.", }) @@ -306,7 +306,7 @@ func NewHTTPClient(addr string, client *http.Client) (*HTTPClient, error) { } url, err := url.Parse(a.String()) if err != nil { - return nil, NewError(InvalidAddress, map[string]interface{}{ + return nil, NewError(AddressError, map[string]interface{}{ "url": a.String(), "method": "url.Parse", "error": err.Error(), Modified: v2/libgrn/conn.go (+3 -3) =================================================================== --- v2/libgrn/conn.go 2017-07-11 10:49:59 +0900 (872dd65) +++ v2/libgrn/conn.go 2017-07-11 11:02:23 +0900 (7da73c9) @@ -89,7 +89,7 @@ func Create(path string) (*Conn, error) { // Dup duplicates the Conn if it is a DB handle. func (c *Conn) Dup() (*Conn, error) { if c.db == nil { - return nil, grnci.NewError(grnci.InvalidOperation, map[string]interface{}{ + return nil, grnci.NewError(grnci.OperationError, map[string]interface{}{ "error": "GQTP clients do not support Dup.", }) } @@ -265,12 +265,12 @@ func (c *Conn) execBody(cmd string, body io.Reader) (grnci.Response, error) { // exec sends a command and receives a response. func (c *Conn) exec(cmd string, body io.Reader) (grnci.Response, error) { if !c.ready { - return nil, grnci.NewError(grnci.InvalidOperation, map[string]interface{}{ + return nil, grnci.NewError(grnci.OperationError, map[string]interface{}{ "error": "The connection is not ready to send a command.", }) } if len(cmd) > maxChunkSize { - return nil, grnci.NewError(grnci.InvalidCommand, map[string]interface{}{ + return nil, grnci.NewError(grnci.CommandError, map[string]interface{}{ "length": len(cmd), "error": "The command is too long.", }) Modified: v2/libgrn/libgrn.go (+2 -2) =================================================================== --- v2/libgrn/libgrn.go 2017-07-11 10:49:59 +0900 (030983e) +++ v2/libgrn/libgrn.go 2017-07-11 11:02:23 +0900 (48a0d18) @@ -63,7 +63,7 @@ func Fin() error { libMutex.Lock() defer libMutex.Unlock() if libCount <= 0 { - return grnci.NewError(grnci.InvalidOperation, map[string]interface{}{ + return grnci.NewError(grnci.OperationError, map[string]interface{}{ "libCount": libCount, "error": "libCount must be greater than 0.", }) @@ -227,7 +227,7 @@ func (db *grnDB) Close(ctx *grnCtx) error { db.mutex.Lock() defer db.mutex.Unlock() if db.count <= 0 { - return grnci.NewError(grnci.InvalidOperation, map[string]interface{}{ + return grnci.NewError(grnci.OperationError, map[string]interface{}{ "count": db.count, "error": "count must be greater than 0.", }) Modified: v2/type.go (+22 -22) =================================================================== --- v2/type.go 2017-07-11 10:49:59 +0900 (bae1302) +++ v2/type.go 2017-07-11 11:02:23 +0900 (9104bc5) @@ -45,19 +45,19 @@ type ColumnField struct { func checkTableName(s string) error { switch s { case "": - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": s, "error": "A table name must not be empty.", }) case "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Float", "ShortText", "Text", "LongText", "Time", "WGS84GeoPoint", "TokyoGeoPoint": - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": s, "error": "The name specifies a built-in type and not available as a table name.", }) } if s[0] == '_' { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": s, "error": "A table name must not start with '_'.", }) @@ -69,7 +69,7 @@ func checkTableName(s string) error { case c >= 'a' && c <= 'z': case c == '_': default: - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": s, "error": "A table name must consist of [0-9A-Za-z_].", }) @@ -81,7 +81,7 @@ func checkTableName(s string) error { // parseIDOptions parses options of _id. func (cf *ColumnField) parseIDOptions(options []string) error { if len(options) > 1 { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": cf.Name, "options": options, "error": "The tag must not contain more than one option.", @@ -95,7 +95,7 @@ func (cf *ColumnField) parseIDOptions(options []string) error { cf.Type = "UInt32" case "UInt32": default: - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": cf.Type, "error": "The type is not supported as _id.", }) @@ -141,7 +141,7 @@ func (cf *ColumnField) checkKeyType() error { } } if cf.Type == "" { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": reflect.TypeOf(cf.Field.Type).Name(), "error": "The type is not supported as _key.", }) @@ -150,7 +150,7 @@ func (cf *ColumnField) checkKeyType() error { "Float", "ShortText", "Time", "WGS84GeoPoint", "TokyoGeoPoint": default: if err := checkTableName(cf.Type); err != nil { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": cf.Type, "error": "The type is not supported as _key.", }) @@ -171,7 +171,7 @@ func (cf *ColumnField) checkKey() error { // parseKeyOptions parses options of _key. func (cf *ColumnField) parseKeyOptions(options []string) error { if len(options) > 5 { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": cf.Name, "options": options, "error": "The tag must not contain more than 5 options.", @@ -237,7 +237,7 @@ func (cf *ColumnField) checkValue() error { } } if cf.Type == "" { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": reflect.TypeOf(cf.Field.Type).Name(), "error": "The type is not supported as _value.", }) @@ -245,7 +245,7 @@ func (cf *ColumnField) checkValue() error { case "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Float", "Time", "WGS84GeoPoint", "TokyoGeoPoint": default: - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": cf.Type, "error": "The type is not supported as _value.", }) @@ -256,7 +256,7 @@ func (cf *ColumnField) checkValue() error { // parseValueOptions parses options of _value. func (cf *ColumnField) parseValueOptions(options []string) error { if len(options) > 1 { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": cf.Name, "options": options, "error": "The tag must not contain more than one option.", @@ -275,7 +275,7 @@ func (cf *ColumnField) parseValueOptions(options []string) error { // parseScoreOptions parses options of _score. func (cf *ColumnField) parseScoreOptions(options []string) error { if len(options) > 1 { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": cf.Name, "options": options, "error": "The tag must not contain more than one option.", @@ -291,7 +291,7 @@ func (cf *ColumnField) parseScoreOptions(options []string) error { cf.Type = "Float" case "Int32", "Float": default: - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": cf.Type, "error": "The type is not supported as _score.", }) @@ -347,7 +347,7 @@ Loop: } } if cf.Type == "" { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": reflect.TypeOf(cf.Field.Type).Name(), "error": "The type is not supported as a column.", }) @@ -372,7 +372,7 @@ func (cf *ColumnField) checkColumnType() error { "Float", "ShortText", "Text", "LongText", "Time", "WGS84GeoPoint", "TokyoGeoPoint": default: if err := checkTableName(typ); err != nil { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "type": cf.Type, "error": "The type is not supported as a column.", }) @@ -386,13 +386,13 @@ func (cf *ColumnField) checkColumnType() error { func (cf *ColumnField) checkColumnName() error { s := cf.Name if s == "" { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": s, "error": "A column name must not be empty.", }) } if s[0] == '_' { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": s, "error": "A column name must not start with '_'.", }) @@ -433,7 +433,7 @@ func (cf *ColumnField) checkColumn() error { // parseColumnOptions parses options of a column. func (cf *ColumnField) parseColumnOptions(options []string) error { if len(options) > 2 { - return NewError(InvalidType, map[string]interface{}{ + return NewError(TypeError, map[string]interface{}{ "name": cf.Name, "options": options, "error": "The tag must not contain more than 2 options.", @@ -468,7 +468,7 @@ func (cf *ColumnField) parseOptions(options []string) error { func newColumnField(field *reflect.StructField, index int) (*ColumnField, error) { tag := field.Tag.Get(columnFieldTagKey) if tag == "" { - return nil, NewError(InvalidType, map[string]interface{}{ + return nil, NewError(TypeError, map[string]interface{}{ "name": field.Name, "tag": field.Tag, "error": "The struct field must have a non-empty " + columnFieldTagKey + " tag.", @@ -508,7 +508,7 @@ Loop: case reflect.Struct: break Loop default: - return nil, NewError(InvalidType, map[string]interface{}{ + return nil, NewError(TypeError, map[string]interface{}{ "type": reflect.TypeOf(v).Name(), "error": "The type is not supported as a row struct.", }) @@ -539,7 +539,7 @@ Loop: cfs = append(cfs, cf) } if _, ok := cfsByName[cf.Name]; ok { - return nil, NewError(InvalidType, map[string]interface{}{ + return nil, NewError(TypeError, map[string]interface{}{ "name": cf.Name, "error": "The name appears more than once.", }) -------------- next part -------------- HTML����������������������������...Download