Susumu Yata
null+****@clear*****
Wed Aug 2 16:56:59 JST 2017
Susumu Yata 2017-08-02 16:56:59 +0900 (Wed, 02 Aug 2017) New Revision: 606e881c099a8dfac0138825cbf63be8e635d92c https://github.com/groonga/grnci/commit/606e881c099a8dfac0138825cbf63be8e635d92c Message: Rename NewError2 to NewError. 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/libgrn/response.go v2/type.go Modified: v2/address.go (+11 -11) =================================================================== --- v2/address.go 2017-08-02 16:53:49 +0900 (c13bd0f) +++ v2/address.go 2017-08-02 16:56:59 +0900 (79af3a6) @@ -40,12 +40,12 @@ func (a *Address) fillGQTP() error { a.Scheme = "gqtp" } if a.Username != "" { - return NewError2(AddressError, "GQTP does not accept username.", map[string]interface{}{ + return NewError(AddressError, "GQTP does not accept username.", map[string]interface{}{ "username": a.Username, }) } if a.Password != "" { - return NewError2(AddressError, "GQTP does not accept password.", map[string]interface{}{ + return NewError(AddressError, "GQTP does not accept password.", map[string]interface{}{ "password": a.Password, }) } @@ -56,17 +56,17 @@ func (a *Address) fillGQTP() error { a.Port = DefaultGQTPPort } if a.Path != "" { - return NewError2(AddressError, "GQTP does not accept path.", map[string]interface{}{ + return NewError(AddressError, "GQTP does not accept path.", map[string]interface{}{ "path": a.Path, }) } if a.Query != "" { - return NewError2(AddressError, "GQTP does not accept query.", map[string]interface{}{ + return NewError(AddressError, "GQTP does not accept query.", map[string]interface{}{ "query": a.Query, }) } if a.Fragment != "" { - return NewError2(AddressError, "GQTP does not accept fragment.", map[string]interface{}{ + return NewError(AddressError, "GQTP does not accept fragment.", map[string]interface{}{ "fragment": a.Fragment, }) } @@ -105,7 +105,7 @@ func (a *Address) fill() error { return err } default: - return NewError2(AddressError, "The scheme is not supported.", map[string]interface{}{ + return NewError(AddressError, "The scheme is not supported.", map[string]interface{}{ "scheme": a.Scheme, }) } @@ -121,7 +121,7 @@ func (a *Address) parseHostPort(s string) error { if s[0] == '[' { i := strings.IndexByte(s, ']') if i == -1 { - return NewError2(AddressError, "IPv6 address must be enclosed in [].", map[string]interface{}{ + return NewError(AddressError, "IPv6 address must be enclosed in [].", map[string]interface{}{ "address": s, }) } @@ -131,7 +131,7 @@ func (a *Address) parseHostPort(s string) error { return nil } if rest[0] != ':' { - return NewError2(AddressError, "IPv6 address and port must be separated by ':'.", map[string]interface{}{ + return NewError(AddressError, "IPv6 address and port must be separated by ':'.", map[string]interface{}{ "address": s, }) } @@ -148,7 +148,7 @@ func (a *Address) parseHostPort(s string) error { if portStr != "" { port, err := net.LookupPort("tcp", portStr) if err != nil { - return NewError2(AddressError, "net.LookupPort failed.", map[string]interface{}{ + return NewError(AddressError, "net.LookupPort failed.", map[string]interface{}{ "port": portStr, "error": err.Error(), }) @@ -231,7 +231,7 @@ func ParseGQTPAddress(s string) (*Address, error) { switch strings.ToLower(a.Scheme) { case "", "gqtp": default: - return nil, NewError2(AddressError, "The scheme is not supported.", map[string]interface{}{ + return nil, NewError(AddressError, "The scheme is not supported.", map[string]interface{}{ "scheme": a.Scheme, }) } @@ -257,7 +257,7 @@ func ParseHTTPAddress(s string) (*Address, error) { switch strings.ToLower(a.Scheme) { case "", "http", "https": default: - return nil, NewError2(AddressError, "The scheme is not supported.", map[string]interface{}{ + return nil, NewError(AddressError, "The scheme is not supported.", map[string]interface{}{ "scheme": a.Scheme, }) } Modified: v2/command.go (+19 -19) =================================================================== --- v2/command.go 2017-08-02 16:53:49 +0900 (b6e1b20) +++ v2/command.go 2017-08-02 16:56:59 +0900 (2b09a18) @@ -32,7 +32,7 @@ func formatParamValue(key string, value interface{}) (string, error) { case reflect.String: return v.String(), nil default: - return "", NewError2(CommandError, "The type is not supported.", map[string]interface{}{ + return "", NewError(CommandError, "The type is not supported.", map[string]interface{}{ "key": key, "value": value, "type": reflect.TypeOf(value).Name(), @@ -53,13 +53,13 @@ func formatParamBoolean(key string, value interface{}, t, f string) (string, err case t, f: return v, nil default: - return "", NewError2(CommandError, fmt.Sprintf("The value must be %s or %s.", t, f), map[string]interface{}{ + return "", NewError(CommandError, fmt.Sprintf("The value must be %s or %s.", t, f), map[string]interface{}{ "key": key, "value": v, }) } default: - return "", NewError2(CommandError, "The type is not supported.", map[string]interface{}{ + return "", NewError(CommandError, "The type is not supported.", map[string]interface{}{ "key": key, "value": value, "type": reflect.TypeOf(value).Name(), @@ -96,7 +96,7 @@ func formatParamDelim(key string, value interface{}, delim string) (string, erro } return string(buf), nil } - return "", NewError2(CommandError, "The type is not supported.", map[string]interface{}{ + return "", NewError(CommandError, "The type is not supported.", map[string]interface{}{ "key": key, "value": value, "type": reflect.TypeOf(value).Name(), @@ -152,7 +152,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 "", NewError2(CommandError, "The key must not be empty.", map[string]interface{}{ + return "", NewError(CommandError, "The key must not be empty.", map[string]interface{}{ "key": key, "value": value, }) @@ -162,7 +162,7 @@ func formatParamDefault(key string, value interface{}) (string, error) { case c >= 'a' && c <= 'z': case c == '_': default: - return "", NewError2(CommandError, "The key must consist of [a-z_].", map[string]interface{}{ + return "", NewError(CommandError, "The key must consist of [a-z_].", map[string]interface{}{ "key": key, "value": value, }) @@ -174,7 +174,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 "", NewError2(CommandError, "The key must not be empty.", map[string]interface{}{ + return "", NewError(CommandError, "The key must not be empty.", map[string]interface{}{ "key": key, "value": value, }) @@ -188,7 +188,7 @@ func formatParamSelect(key string, value interface{}) (string, error) { switch c { case '#', '@', '-', '_', '.', '[', ']': default: - return "", NewError2(CommandError, "The key must consist of [0-9A-Za-z#@-_.[]].", map[string]interface{}{ + return "", NewError(CommandError, "The key must consist of [0-9A-Za-z#@-_.[]].", map[string]interface{}{ "key": key, "value": value, }) @@ -620,7 +620,7 @@ type Command struct { func newCommand(name string) (*Command, error) { format := getCommandFormat(name) if format == nil { - return nil, NewError2(CommandError, "The name is not defined.", map[string]interface{}{ + return nil, NewError(CommandError, "The name is not defined.", map[string]interface{}{ "name": name, }) } @@ -685,7 +685,7 @@ func tokenizeCommand(cmd string) ([]string, error) { } i++ if i == len(s) { - return nil, NewError2(CommandError, "The command ends with an unclosed token.", map[string]interface{}{ + return nil, NewError(CommandError, "The command ends with an unclosed token.", map[string]interface{}{ "command": cmd, }) } @@ -702,7 +702,7 @@ func tokenizeCommand(cmd string) ([]string, error) { case '\\': i++ if i == len(s) { - return nil, NewError2(CommandError, "The command ends with an escape character.", map[string]interface{}{ + return nil, NewError(CommandError, "The command ends with an escape character.", map[string]interface{}{ "command": cmd, }) } @@ -734,7 +734,7 @@ func ParseCommand(cmd string) (*Command, error) { return nil, err } if len(tokens) == 0 { - return nil, NewError2(CommandError, "The command has no tokens.", map[string]interface{}{ + return nil, NewError(CommandError, "The command has no tokens.", map[string]interface{}{ "command": cmd, }) } @@ -749,7 +749,7 @@ func ParseCommand(cmd string) (*Command, error) { k = tokens[i][2:] i++ if i >= len(tokens) { - return nil, NewError2(CommandError, "The key requires a value.", map[string]interface{}{ + return nil, NewError(CommandError, "The key requires a value.", map[string]interface{}{ "command": cmd, "key": k, }) @@ -793,7 +793,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 NewError2(CommandError, "The command requires the key.", map[string]interface{}{ + return NewError(CommandError, "The command requires the key.", map[string]interface{}{ "name": c.name, "params": c.params, "key": pf.key, @@ -801,13 +801,13 @@ func (c *Command) Check() error { } } if !c.NeedsBody() && c.body != nil { - return NewError2(CommandError, "The command does not require a body", map[string]interface{}{ + return NewError(CommandError, "The command does not require a body", map[string]interface{}{ "name": c.name, "params": c.params, }) } if c.NeedsBody() && c.body == nil { - return NewError2(CommandError, "The command requires a body", map[string]interface{}{ + return NewError(CommandError, "The command requires a body", map[string]interface{}{ "name": c.name, "params": c.params, }) @@ -821,7 +821,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 NewError2(CommandError, "The key does not exist.", map[string]interface{}{ + return NewError(CommandError, "The key does not exist.", map[string]interface{}{ "name": c.name, "key": key, }) @@ -831,7 +831,7 @@ func (c *Command) SetParam(key string, value interface{}) error { } if key == "" { if c.index >= len(c.format.params) { - return NewError2(CommandError, "The index is too large.", map[string]interface{}{ + return NewError(CommandError, "The index is too large.", map[string]interface{}{ "name": c.name, "index": c.index, }) @@ -1030,7 +1030,7 @@ func (cr *CommandReader) fill() error { if err != nil { cr.err = err if err != io.EOF { - cr.err = NewError2(InputError, "CommandReader.reader.Read failed.", map[string]interface{}{ + cr.err = NewError(InputError, "CommandReader.reader.Read failed.", map[string]interface{}{ "error": err.Error(), }) } Modified: v2/db.go (+80 -83) =================================================================== --- v2/db.go 2017-08-02 16:53:49 +0900 (e247fa6) +++ v2/db.go 2017-08-02 16:56:59 +0900 (18647fa) @@ -33,7 +33,7 @@ func (db *DB) recvBool(resp Response) (bool, Response, error) { if resp.Err() != nil { return false, resp, nil } - return false, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -52,7 +52,7 @@ func (db *DB) recvInt(resp Response) (int, Response, error) { if resp.Err() != nil { return 0, resp, nil } - return 0, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -71,7 +71,7 @@ func (db *DB) recvString(resp Response) (string, Response, error) { if resp.Err() != nil { return "", resp, nil } - return "", resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return "", resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -98,14 +98,14 @@ 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, NewError2(CommandError, "The from must contain a dot.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The from must contain a dot.", map[string]interface{}{ "from": from, }) } fromTable := from[:i] fromName := from[i+1:] if i = strings.IndexByte(to, '.'); i == -1 { - return false, nil, NewError2(CommandError, "The to must contain a dot.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The to must contain a dot.", map[string]interface{}{ "to": to, }) } @@ -127,7 +127,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, NewError2(CommandError, "The name must contain a dot.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The name must contain a dot.", map[string]interface{}{ "name": name, }) } @@ -191,12 +191,12 @@ func (db *DB) ColumnList(tbl string) ([]DBColumn, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } if len(result) == 0 { - return nil, resp, NewError2(ResponseError, "The result is empty.", nil) + return nil, resp, NewError(ResponseError, "The result is empty.", nil) } var fields []string for _, meta := range result[0] { @@ -258,7 +258,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, NewError2(CommandError, "The name must contain a dot.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The name must contain a dot.", map[string]interface{}{ "name": name, }) } @@ -276,13 +276,13 @@ 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, NewError2(CommandError, "The name must contain a dot.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The name must contain a dot.", map[string]interface{}{ "name": name, }) } if j := strings.IndexByte(newName, '.'); j != -1 { if i != j || name[:i] != newName[:i] { - return false, nil, NewError2(CommandError, "The names have different table names.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The names have different table names.", map[string]interface{}{ "name": name, "newName": newName, }) @@ -533,7 +533,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, NewError2(CommandError, "The column has no associated field.", map[string]interface{}{ + return 0, nil, NewError(CommandError, "The column has no associated field.", map[string]interface{}{ "column": col, }) } @@ -546,11 +546,11 @@ func (db *DB) LoadRows(tbl string, rows interface{}, options *DBLoadOptions) (in switch v.Kind() { case reflect.Ptr: if v.IsNil() { - return 0, nil, NewError2(CommandError, "The rows must not be nil.", nil) + return 0, nil, NewError(CommandError, "The rows must not be nil.", nil) } v = v.Elem() if v.Kind() != reflect.Struct { - return 0, nil, NewError2(CommandError, "The type is not supported.", map[string]interface{}{ + return 0, nil, NewError(CommandError, "The type is not supported.", map[string]interface{}{ "type": reflect.TypeOf(rows).Name(), }) } @@ -560,7 +560,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, NewError2(CommandError, "The type is not supported.", map[string]interface{}{ + return 0, nil, NewError(CommandError, "The type is not supported.", map[string]interface{}{ "type": reflect.TypeOf(rows).Name(), }) } @@ -716,7 +716,7 @@ func (db *DB) LogicalParameters(rangeIndex string) (*DBLogicalParameters, Respon if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -853,7 +853,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, NewError2(CommandError, "The column has no associated field.", map[string]interface{}{ + return 0, nil, NewError(CommandError, "The column has no associated field.", map[string]interface{}{ "column": col, }) } @@ -899,7 +899,7 @@ func (db *DB) LogicalShardList(logicalTable string) ([]DBLogicalShard, Response, if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -980,7 +980,7 @@ func (db *DB) Normalize(normalizer, str string, flags []string) (*DBNormalizedTe if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1008,9 +1008,8 @@ func (db *DB) NormalizerList() ([]DBNormalizer, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(ResponseError, map[string]interface{}{ - "method": "json.Unmarshal", - "error": err.Error(), + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + "error": err.Error(), }) } return result, resp, nil @@ -1143,7 +1142,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1154,7 +1153,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1169,9 +1168,8 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError(ResponseError, map[string]interface{}{ - "method": "json.Unmarshal", - "error": err.Error(), + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + "error": err.Error(), }) } switch { @@ -1181,7 +1179,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1192,7 +1190,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1201,7 +1199,7 @@ func (db *DB) ObjectInspect(name string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "The response format is not invalid.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "The response format is not invalid.", map[string]interface{}{ "command": "object_inspect", }) } @@ -1247,7 +1245,7 @@ func (db *DB) ObjectList() (map[string]*DBObject, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1331,14 +1329,14 @@ func (db *DB) Restore(r io.Reader, w io.Writer, stopOnError bool) (n int, err er if w != nil { if _, e = io.Copy(w, resp); e != nil && err == nil { if _, ok := e.(*Error); !ok { - e = NewError2(OutputError, "io.Copy failed.", map[string]interface{}{ + e = NewError(OutputError, "io.Copy failed.", map[string]interface{}{ "error": e.Error(), }) } err = e } if _, e := w.Write([]byte("\n")); e != nil && err == nil { - err = NewError2(OutputError, "io.Writer.Write", map[string]interface{}{ + err = NewError(OutputError, "io.Writer.Write", map[string]interface{}{ "error": e.Error(), }) } @@ -1378,7 +1376,7 @@ func (db *DB) RequestCancel(id int) (bool, Response, error) { if resp.Err() != nil { return false, resp, nil } - return false, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1406,9 +1404,8 @@ func (db *DB) RubyEval(script string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return false, resp, NewError(ResponseError, map[string]interface{}{ - "method": "json.Unmarshal", - "error": err.Error(), + return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + "error": err.Error(), }) } return result.Value, resp, nil @@ -1435,7 +1432,7 @@ func (db *DB) RubyLoad(path string) (interface{}, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return false, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return false, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1560,7 +1557,7 @@ func (db *DB) Schema() (*DBSchema, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1774,7 +1771,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, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1794,7 +1791,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, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -1813,7 +1810,7 @@ func (db *DB) parseRows(rows interface{}, data []byte, cfs []*ColumnField) (int, } } if nCols != len(cfs) { - return 0, NewError2(ResponseError, "nFields and nColumns must be same.", map[string]interface{}{ + return 0, NewError(ResponseError, "nFields and nColumns must be same.", map[string]interface{}{ "nFields": len(cfs), "nCols": nCols, }) @@ -1843,184 +1840,184 @@ 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, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *int: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *int8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *int16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *int32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *int64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *uint: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *uint8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *uint16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *uint32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *uint64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *float32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *float64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *string: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *time.Time: var f float64 if err := json.Unmarshal(rawRecs[i][j], &f); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } *v = time.Unix(int64(f), int64(f*1000000)%1000000) case *[]bool: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]int: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]int8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]int16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]int32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]int64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]uint: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]uint8: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]uint16: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]uint32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]uint64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]float32: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]float64: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]string: if err := json.Unmarshal(rawRecs[i][j], v); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } case *[]time.Time: var f []float64 if err := json.Unmarshal(rawRecs[i][j], &f); err != nil { - return 0, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return 0, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -2054,7 +2051,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, NewError2(CommandError, "The column has no associated field.", map[string]interface{}{ + return 0, nil, NewError(CommandError, "The column has no associated field.", map[string]interface{}{ "column": col, }) } @@ -2121,7 +2118,7 @@ func (db *DB) Status() (*DBStatus, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -2217,12 +2214,12 @@ func (db *DB) TableCreate(name string, options *DBTableCreateOptions) (bool, Res switch flag { case "TABLE_NO_KEY": if keyFlag != "" { - return false, nil, NewError2(CommandError, "The combination of flags is wrong.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The combination of flags is wrong.", map[string]interface{}{ "flags": flags, }) } if options.KeyType != "" { - return false, nil, NewError2(CommandError, "TABLE_NO_KEY denies key_type.", map[string]interface{}{ + return false, nil, NewError(CommandError, "TABLE_NO_KEY denies key_type.", map[string]interface{}{ "flags": flags, "key_type": options.KeyType, }) @@ -2230,12 +2227,12 @@ 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, NewError2(CommandError, "The combination of flags is wrong.", map[string]interface{}{ + return false, nil, NewError(CommandError, "The combination of flags is wrong.", map[string]interface{}{ "flags": flags, }) } if options.KeyType == "" { - return false, nil, NewError2(CommandError, fmt.Sprintf("%s requires key_type.", flag), map[string]interface{}{ + return false, nil, NewError(CommandError, fmt.Sprintf("%s requires key_type.", flag), map[string]interface{}{ "flags": flags, "key_type": options.KeyType, }) @@ -2305,12 +2302,12 @@ func (db *DB) TableList() ([]DBTable, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } if len(result) == 0 { - return nil, resp, NewError2(ResponseError, "The result is empty.", nil) + return nil, resp, NewError(ResponseError, "The result is empty.", nil) } var fields []string for _, meta := range result[0] { @@ -2439,7 +2436,7 @@ func (db *DB) TableTokenize(tbl, str string, options *DBTableTokenizeOptions) ([ if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -2510,7 +2507,7 @@ func (db *DB) Tokenize(tokenizer, str string, options *DBTokenizeOptions) ([]DBT if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -2538,7 +2535,7 @@ func (db *DB) TokenizerList() ([]DBTokenizer, Response, error) { if resp.Err() != nil { return nil, resp, nil } - return nil, resp, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, resp, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "error": err.Error(), }) } Modified: v2/error.go (+1 -13) =================================================================== --- v2/error.go 2017-08-02 16:53:49 +0900 (f52d2c7) +++ v2/error.go 2017-08-02 16:56:59 +0900 (b361a14) @@ -249,19 +249,7 @@ type Error struct { } // NewError returns a new Error. -func NewError(code ErrorCode, data map[string]interface{}) *Error { - err := &Error{ - Code: code, - Data: make(map[string]interface{}), - } - for k, v := range data { - err.Data[k] = v - } - return err -} - -// NewError2 returns a new Error. -func NewError2(code ErrorCode, msg string, data map[string]interface{}) *Error { +func NewError(code ErrorCode, msg string, data map[string]interface{}) *Error { err := &Error{ Code: code, Message: msg, Modified: v2/error_test.go (+4 -20) =================================================================== --- v2/error_test.go 2017-08-02 16:53:49 +0900 (d883b2e) +++ v2/error_test.go 2017-08-02 16:56:59 +0900 (7e6b266) @@ -32,33 +32,17 @@ func TestErrorCode(t *testing.T) { } func TestNewError(t *testing.T) { + msg := "This is a test of NewError." data := map[string]interface{}{ "string": "value", "int": 100, } - err := NewError(AddressError, data) + err := NewError(AddressError, msg, data) if err.Code != AddressError { - t.Fatalf("NewError failed: Code: actual = %d, want = %d", err.Code, AddressError) - } - for k, v := range data { - if err.Data[k] != v { - t.Fatalf("NewError failed: Data[\"%s\"]: actual = %s, want = %s", k, err.Data[k], v) - } - } -} - -func TestNewError2(t *testing.T) { - msg := "This is a test of NewError2." - data := map[string]interface{}{ - "string": "value", - "int": 100, - } - err := NewError2(AddressError, msg, data) - if err.Code != AddressError { - t.Fatalf("NewError2 failed: Code = %d, want = %d", err.Code, AddressError) + t.Fatalf("NewError failed: Code = %d, want = %d", err.Code, AddressError) } if err.Message != msg { - t.Fatalf("NewError2 failed: Message = %s, want = %s", err.Message, msg) + t.Fatalf("NewError failed: Message = %s, want = %s", err.Message, msg) } for k, v := range data { if err.Data[k] != v { Modified: v2/gqtp.go (+12 -12) =================================================================== --- v2/gqtp.go 2017-08-02 16:53:49 +0900 (47f2b78) +++ v2/gqtp.go 2017-08-02 16:56:59 +0900 (3c4dd75) @@ -63,7 +63,7 @@ func newGQTPResponse(conn *gqtpConn, head gqtpHeader) *gqtpResponse { } if head.Status > 32767 { rc := int(head.Status) - 65536 - resp.err = NewError2(ErrorCode(rc), "Error response received.", nil) + resp.err = NewError(ErrorCode(rc), "Error response received.", nil) } return resp } @@ -106,7 +106,7 @@ func (r *gqtpResponse) Read(p []byte) (int, error) { } if err != nil { r.conn.broken = true - return n, NewError2(NetworkError, "net.Conn.Read failed.", map[string]interface{}{ + return n, NewError(NetworkError, "net.Conn.Read failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -121,7 +121,7 @@ func (r *gqtpResponse) Close() error { var err error if _, e := io.CopyBuffer(ioutil.Discard, r, r.conn.buf); e != nil { r.conn.broken = true - err = NewError2(NetworkError, "io.CopyBuffer failed.", map[string]interface{}{ + err = NewError(NetworkError, "io.CopyBuffer failed.", map[string]interface{}{ "error": e.Error(), }) } @@ -182,7 +182,7 @@ func dialGQTP(addr string, options *gqtpConnOptions) (*gqtpConn, error) { } conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", a.Host, a.Port)) if err != nil { - return nil, NewError2(NetworkError, "net.Dial failed.", map[string]interface{}{ + return nil, NewError(NetworkError, "net.Dial failed.", map[string]interface{}{ "host": a.Host, "port": a.Port, "error": err.Error(), @@ -206,7 +206,7 @@ func newGQTPConn(conn net.Conn, options *gqtpConnOptions) *gqtpConn { // Close closes the connection. func (c *gqtpConn) Close() error { if err := c.conn.Close(); err != nil { - return NewError2(NetworkError, "net.Conn.Close failed.", map[string]interface{}{ + return NewError(NetworkError, "net.Conn.Close failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -221,7 +221,7 @@ func (c *gqtpConn) sendHeader(flags byte, size int) error { Size: uint32(size), } if err := binary.Write(c.conn, binary.BigEndian, head); err != nil { - return NewError2(NetworkError, "binary.Write failed.", map[string]interface{}{ + return NewError(NetworkError, "binary.Write failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -234,7 +234,7 @@ func (c *gqtpConn) sendChunkBytes(data []byte, flags byte) error { return err } if _, err := c.conn.Write(data); err != nil { - return NewError2(NetworkError, "net.Conn.Write failed.", map[string]interface{}{ + return NewError(NetworkError, "net.Conn.Write failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -247,7 +247,7 @@ func (c *gqtpConn) sendChunkString(data string, flags byte) error { return err } if _, err := io.WriteString(c.conn, data); err != nil { - return NewError2(NetworkError, "io.WriteString failed.", map[string]interface{}{ + return NewError(NetworkError, "io.WriteString failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -258,7 +258,7 @@ func (c *gqtpConn) sendChunkString(data string, flags byte) error { func (c *gqtpConn) recvHeader() (gqtpHeader, error) { var head gqtpHeader if err := binary.Read(c.conn, binary.BigEndian, &head); err != nil { - return head, NewError2(NetworkError, "binary.Read failed.", map[string]interface{}{ + return head, NewError(NetworkError, "binary.Read failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -322,13 +322,13 @@ func (c *gqtpConn) execBody(cmd string, body io.Reader) (Response, error) { // Exec sends a command and receives a response. func (c *gqtpConn) Exec(cmd string, body io.Reader) (Response, error) { if c.broken { - return nil, NewError2(OperationError, "The connection is broken.", nil) + return nil, NewError(OperationError, "The connection is broken.", nil) } if !c.ready { - return nil, NewError2(OperationError, "The connection is not ready to send a command.", nil) + return nil, NewError(OperationError, "The connection is not ready to send a command.", nil) } if len(cmd) > gqtpMaxChunkSize { - return nil, NewError2(CommandError, "The command is too long.", + return nil, NewError(CommandError, "The command is too long.", map[string]interface{}{"length": len(cmd)}) } c.ready = false Modified: v2/http.go (+18 -18) =================================================================== --- v2/http.go 2017-08-02 16:53:49 +0900 (137b9a1) +++ v2/http.go 2017-08-02 16:56:59 +0900 (3f6c7ae) @@ -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 = NewError2(ResponseError, "The response does not contain a header.", map[string]interface{}{ + err = NewError(ResponseError, "The response does not contain a header.", map[string]interface{}{ "data": string(data), }) return @@ -48,7 +48,7 @@ Loop: stack = append(stack, '}') case ']', '}': if left[i] != stack[len(stack)-1] { - err = NewError2(ResponseError, "The response header is broken.", map[string]interface{}{ + err = NewError(ResponseError, "The response header is broken.", map[string]interface{}{ "data": string(data), }) return @@ -70,7 +70,7 @@ Loop: } } if len(stack) != 0 { - err = NewError2(ResponseError, "The response header is too long or broken.", map[string]interface{}{ + err = NewError(ResponseError, "The response header is too long or broken.", map[string]interface{}{ "data": string(data), }) return @@ -85,7 +85,7 @@ Loop: // parseHTTPResponseHeaderError parses the error information in the HTTP resonse header. func parseHTTPResponseHeaderError(rc int, elems []interface{}) error { - err := NewError2(ErrorCode(rc), "Error response received.", nil) + err := NewError(ErrorCode(rc), "Error response received.", nil) if len(elems) >= 1 { err.Data["message"] = elems[0] } @@ -125,26 +125,26 @@ func parseHTTPResponseHeader(resp *http.Response, data []byte) (*httpResponse, e // TODO: use another JSON decoder. var elems []interface{} if err := json.Unmarshal(head, &elems); err != nil { - return nil, NewError2(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ + return nil, NewError(ResponseError, "json.Unmarshal failed.", map[string]interface{}{ "head": string(head), "error": err.Error(), }) } if len(elems) < 3 { - return nil, NewError2(ResponseError, "Too few elements in the response header.", map[string]interface{}{ + return nil, NewError(ResponseError, "Too few elements in the response header.", map[string]interface{}{ "elems": elems, }) } f, ok := elems[0].(float64) if !ok { - return nil, NewError2(ResponseError, "The 1st element must be the result code (number).", map[string]interface{}{ + return nil, NewError(ResponseError, "The 1st element must be the result code (number).", map[string]interface{}{ "elems": elems, }) } rc := int(f) f, ok = elems[1].(float64) if !ok { - return nil, NewError2(ResponseError, "The 2nd element must be the start time (number).", map[string]interface{}{ + return nil, NewError(ResponseError, "The 2nd element must be the start time (number).", map[string]interface{}{ "elems": elems, }) } @@ -152,7 +152,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, NewError2(ResponseError, "The 3rd element must be the elapsed time (number).", map[string]interface{}{ + return nil, NewError(ResponseError, "The 3rd element must be the elapsed time (number).", map[string]interface{}{ "elems": elems, }) } @@ -178,7 +178,7 @@ func newHTTPResponse(resp *http.Response) (*httpResponse, error) { case http.StatusBadRequest: default: resp.Body.Close() - return nil, NewError2(HTTPError, "The status is unexpected.", map[string]interface{}{ + return nil, NewError(HTTPError, "The status is unexpected.", map[string]interface{}{ "status": fmt.Sprintf("%d %s", code, http.StatusText(code)), }) } @@ -187,7 +187,7 @@ func newHTTPResponse(resp *http.Response) (*httpResponse, error) { n, err := io.ReadFull(resp.Body, buf) if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { resp.Body.Close() - return nil, NewError2(NetworkError, "io.ReadFull failed.", map[string]interface{}{ + return nil, NewError(NetworkError, "io.ReadFull failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -239,7 +239,7 @@ func (r *httpResponse) Read(p []byte) (n int, err error) { n-- } if err != io.EOF { - err = NewError2(NetworkError, "http.Response.Body.Read failed.", map[string]interface{}{ + err = NewError(NetworkError, "http.Response.Body.Read failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -258,7 +258,7 @@ func (r *httpResponse) Read(p []byte) (n int, err error) { n-- } if err != io.EOF { - err = NewError2(NetworkError, "http.Response.Body.Read failed.", map[string]interface{}{ + err = NewError(NetworkError, "http.Response.Body.Read failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -269,12 +269,12 @@ func (r *httpResponse) Read(p []byte) (n int, err error) { func (r *httpResponse) Close() error { if _, err := io.Copy(ioutil.Discard, r.resp.Body); err != nil { r.resp.Body.Close() - return NewError2(NetworkError, "io.Copy failed.", map[string]interface{}{ + return NewError(NetworkError, "io.Copy failed.", map[string]interface{}{ "error": err.Error(), }) } if err := r.resp.Body.Close(); err != nil { - return NewError2(NetworkError, "http.Response.Body.Close failed.", map[string]interface{}{ + return NewError(NetworkError, "http.Response.Body.Close failed.", map[string]interface{}{ "error": err.Error(), }) } @@ -303,7 +303,7 @@ func NewHTTPClient(addr string, client *http.Client) (*HTTPClient, error) { } url, err := url.Parse(a.String()) if err != nil { - return nil, NewError2(AddressError, "url.Parse failed.", map[string]interface{}{ + return nil, NewError(AddressError, "url.Parse failed.", map[string]interface{}{ "url": a.String(), "error": err.Error(), }) @@ -336,7 +336,7 @@ func (c *HTTPClient) exec(name string, params map[string]string, body io.Reader) if body == nil { resp, err := c.client.Get(url.String()) if err != nil { - return nil, NewError2(NetworkError, "http.Client.Get failed.", map[string]interface{}{ + return nil, NewError(NetworkError, "http.Client.Get failed.", map[string]interface{}{ "url": url.String(), "error": err.Error(), }) @@ -345,7 +345,7 @@ func (c *HTTPClient) exec(name string, params map[string]string, body io.Reader) } resp, err := c.client.Post(url.String(), "application/json", body) if err != nil { - return nil, NewError2(NetworkError, "http.Client.Post failed.", map[string]interface{}{ + return nil, NewError(NetworkError, "http.Client.Post failed.", map[string]interface{}{ "url": url.String(), "error": err.Error(), }) Modified: v2/libgrn/conn.go (+4 -4) =================================================================== --- v2/libgrn/conn.go 2017-08-02 16:53:49 +0900 (de84728) +++ v2/libgrn/conn.go 2017-08-02 16:56:59 +0900 (19a75c3) @@ -106,7 +106,7 @@ func create(path string, options *connOptions) (*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.NewError2(grnci.OperationError, "GQTP clients do not support Dup.", nil) + return nil, grnci.NewError(grnci.OperationError, "GQTP clients do not support Dup.", nil) } ctx, err := c.db.Dup() if err != nil { @@ -240,13 +240,13 @@ func (c *conn) execDB(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.broken { - return nil, grnci.NewError2(grnci.OperationError, "The connection is broken.", nil) + return nil, grnci.NewError(grnci.OperationError, "The connection is broken.", nil) } if !c.ready { - return nil, grnci.NewError2(grnci.OperationError, "The connection is not ready to send a command.", nil) + return nil, grnci.NewError(grnci.OperationError, "The connection is not ready to send a command.", nil) } if len(cmd) > maxChunkSize { - return nil, grnci.NewError2(grnci.CommandError, "The command is too long.", map[string]interface{}{ + return nil, grnci.NewError(grnci.CommandError, "The command is too long.", map[string]interface{}{ "length": len(cmd), }) } Modified: v2/libgrn/libgrn.go (+10 -10) =================================================================== --- v2/libgrn/libgrn.go 2017-08-02 16:53:49 +0900 (50f3842) +++ v2/libgrn/libgrn.go 2017-08-02 16:56:59 +0900 (19bdd36) @@ -42,7 +42,7 @@ func Init() error { defer libMutex.Unlock() if !initFinDisabled && libCount == 0 { if rc := C.grn_init(); rc != C.GRN_SUCCESS { - return grnci.NewError2(grnci.ErrorCode(rc), "C.grn_init failed.", nil) + return grnci.NewError(grnci.ErrorCode(rc), "C.grn_init failed.", nil) } } libCount++ @@ -60,14 +60,14 @@ func Fin() error { libMutex.Lock() defer libMutex.Unlock() if libCount <= 0 { - return grnci.NewError2(grnci.OperationError, "libCount must be greater than 0.", map[string]interface{}{ + return grnci.NewError(grnci.OperationError, "libCount must be greater than 0.", map[string]interface{}{ "libCount": libCount, }) } libCount-- if !initFinDisabled && libCount == 0 { if rc := C.grn_fin(); rc != C.GRN_SUCCESS { - return grnci.NewError2(grnci.ErrorCode(rc), "C.grn_fin failed.", nil) + return grnci.NewError(grnci.ErrorCode(rc), "C.grn_fin failed.", nil) } } return nil @@ -93,7 +93,7 @@ func newGrnCtx() (*grnCtx, error) { ctx := C.grn_ctx_open(C.int(0)) if ctx == nil { Fin() - return nil, grnci.NewError2(grnci.UnexpectedError, "C.grn_ctx_open failed.", nil) + return nil, grnci.NewError(grnci.UnexpectedError, "C.grn_ctx_open failed.", nil) } return &grnCtx{ctx: ctx}, nil } @@ -101,7 +101,7 @@ func newGrnCtx() (*grnCtx, error) { // Close closes the grnCtx. func (c *grnCtx) Close() error { if rc := C.grn_ctx_close(c.ctx); rc != C.GRN_SUCCESS { - return grnci.NewError2(grnci.ErrorCode(rc), "C.grn_ctx_close failed.", nil) + return grnci.NewError(grnci.ErrorCode(rc), "C.grn_ctx_close failed.", nil) } if err := Fin(); err != nil { return err @@ -127,7 +127,7 @@ func (c *grnCtx) Err(method string) error { if c.ctx.errbuf[0] != 0 { data["error"] = C.GoString(&c.ctx.errbuf[0]) } - return grnci.NewError2(grnci.ErrorCode(c.ctx.rc), method+" failed.", data) + return grnci.NewError(grnci.ErrorCode(c.ctx.rc), method+" failed.", data) } // Send sends data with flags. @@ -180,7 +180,7 @@ func createGrnDB(ctx *grnCtx, path string) (*grnDB, error) { if err := ctx.Err("C.grn_db_create"); err != nil { return nil, err } - return nil, grnci.NewError2(grnci.UnexpectedError, "C.grn_db_create failed.", nil) + return nil, grnci.NewError(grnci.UnexpectedError, "C.grn_db_create failed.", nil) } return &grnDB{ obj: obj, @@ -197,7 +197,7 @@ func openGrnDB(ctx *grnCtx, path string) (*grnDB, error) { if err := ctx.Err("C.grn_db_open"); err != nil { return nil, err } - return nil, grnci.NewError2(grnci.UnexpectedError, "C.grn_db_open failed.", nil) + return nil, grnci.NewError(grnci.UnexpectedError, "C.grn_db_open failed.", nil) } return &grnDB{ obj: obj, @@ -210,7 +210,7 @@ func (db *grnDB) Close(ctx *grnCtx) error { db.mutex.Lock() defer db.mutex.Unlock() if db.count <= 0 { - return grnci.NewError2(grnci.OperationError, "count must be greater than 0.", map[string]interface{}{ + return grnci.NewError(grnci.OperationError, "count must be greater than 0.", map[string]interface{}{ "count": db.count, }) } @@ -220,7 +220,7 @@ func (db *grnDB) Close(ctx *grnCtx) error { if err := ctx.Err("C.grn_obj_close"); err != nil { return err } - return grnci.NewError2(grnci.ErrorCode(rc), "C.grn_obj_close failed.", map[string]interface{}{}) + return grnci.NewError(grnci.ErrorCode(rc), "C.grn_obj_close failed.", map[string]interface{}{}) } db.obj = nil } Modified: v2/libgrn/response.go (+1 -1) =================================================================== --- v2/libgrn/response.go 2017-08-02 16:53:49 +0900 (b34a9ae) +++ v2/libgrn/response.go 2017-08-02 16:56:59 +0900 (8876b9a) @@ -69,7 +69,7 @@ func (r *response) Close() error { if !r.conn.broken { if _, err = io.CopyBuffer(ioutil.Discard, r, r.conn.buf); err != nil { r.conn.broken = true - err = grnci.NewError2(grnci.NetworkError, "io.CopyBuffer failed.", map[string]interface{}{ + err = grnci.NewError(grnci.NetworkError, "io.CopyBuffer failed.", map[string]interface{}{ "error": err.Error(), }) } Modified: v2/type.go (+22 -23) =================================================================== --- v2/type.go 2017-08-02 16:53:49 +0900 (2cfacbf) +++ v2/type.go 2017-08-02 16:56:59 +0900 (eee2699) @@ -45,17 +45,17 @@ type ColumnField struct { func checkTableName(s string) error { switch s { case "": - return NewError2(TypeError, "A table name must not be empty.", map[string]interface{}{ + return NewError(TypeError, "A table name must not be empty.", map[string]interface{}{ "name": s, }) case "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Float", "ShortText", "Text", "LongText", "Time", "WGS84GeoPoint", "TokyoGeoPoint": - return NewError2(TypeError, "The name specifies a built-in type and not available as a table name.", map[string]interface{}{ + return NewError(TypeError, "The name specifies a built-in type and not available as a table name.", map[string]interface{}{ "name": s, }) } if s[0] == '_' { - return NewError2(TypeError, "A table name must not start with '_'.", map[string]interface{}{ + return NewError(TypeError, "A table name must not start with '_'.", map[string]interface{}{ "name": s, }) } @@ -66,7 +66,7 @@ func checkTableName(s string) error { case c >= 'a' && c <= 'z': case c == '_': default: - return NewError2(TypeError, "A table name must consist of [0-9A-Za-z_].", map[string]interface{}{ + return NewError(TypeError, "A table name must consist of [0-9A-Za-z_].", map[string]interface{}{ "name": s, }) } @@ -77,7 +77,7 @@ func checkTableName(s string) error { // parseIDOptions parses options of _id. func (cf *ColumnField) parseIDOptions(options []string) error { if len(options) > 1 { - return NewError2(TypeError, "The tag must not contain more than one option.", map[string]interface{}{ + return NewError(TypeError, "The tag must not contain more than one option.", map[string]interface{}{ "name": cf.Name, "options": options, }) @@ -90,7 +90,7 @@ func (cf *ColumnField) parseIDOptions(options []string) error { cf.Type = "UInt32" case "UInt32": default: - return NewError2(TypeError, "The type is not supported as _id.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as _id.", map[string]interface{}{ "type": cf.Type, }) } @@ -135,7 +135,7 @@ func (cf *ColumnField) checkKeyType() error { } } if cf.Type == "" { - return NewError2(TypeError, "The type is not supported as _key.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as _key.", map[string]interface{}{ "type": reflect.TypeOf(cf.Field.Type).Name(), }) } @@ -143,7 +143,7 @@ func (cf *ColumnField) checkKeyType() error { "Float", "ShortText", "Time", "WGS84GeoPoint", "TokyoGeoPoint": default: if err := checkTableName(cf.Type); err != nil { - return NewError2(TypeError, "The type is not supported as _key.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as _key.", map[string]interface{}{ "type": cf.Type, }) } @@ -163,10 +163,9 @@ func (cf *ColumnField) checkKey() error { // parseKeyOptions parses options of _key. func (cf *ColumnField) parseKeyOptions(options []string) error { if len(options) > 5 { - return NewError(TypeError, map[string]interface{}{ + return NewError(TypeError, "The tag must not contain more than 5 options.", map[string]interface{}{ "name": cf.Name, "options": options, - "error": "The tag must not contain more than 5 options.", }) } if len(options) > 0 { @@ -229,14 +228,14 @@ func (cf *ColumnField) checkValue() error { } } if cf.Type == "" { - return NewError2(TypeError, "The type is not supported as _value.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as _value.", map[string]interface{}{ "type": reflect.TypeOf(cf.Field.Type).Name(), }) } case "Bool", "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64", "Float", "Time", "WGS84GeoPoint", "TokyoGeoPoint": default: - return NewError2(TypeError, "The type is not supported as _value.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as _value.", map[string]interface{}{ "type": cf.Type, }) } @@ -246,7 +245,7 @@ func (cf *ColumnField) checkValue() error { // parseValueOptions parses options of _value. func (cf *ColumnField) parseValueOptions(options []string) error { if len(options) > 1 { - return NewError2(TypeError, "The tag must not contain more than one option.", map[string]interface{}{ + return NewError(TypeError, "The tag must not contain more than one option.", map[string]interface{}{ "name": cf.Name, "options": options, }) @@ -264,7 +263,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 NewError2(TypeError, "The tag must not contain more than one option.", map[string]interface{}{ + return NewError(TypeError, "The tag must not contain more than one option.", map[string]interface{}{ "name": cf.Name, "options": options, }) @@ -279,7 +278,7 @@ func (cf *ColumnField) parseScoreOptions(options []string) error { cf.Type = "Float" case "Int32", "Float": default: - return NewError2(TypeError, "The type is not supported as _score.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as _score.", map[string]interface{}{ "type": cf.Type, }) } @@ -334,7 +333,7 @@ Loop: } } if cf.Type == "" { - return NewError2(TypeError, "The type is not supported as a column.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as a column.", map[string]interface{}{ "type": reflect.TypeOf(cf.Field.Type).Name(), }) } @@ -358,7 +357,7 @@ func (cf *ColumnField) checkColumnType() error { "Float", "ShortText", "Text", "LongText", "Time", "WGS84GeoPoint", "TokyoGeoPoint": default: if err := checkTableName(typ); err != nil { - return NewError2(TypeError, "The type is not supported as a column.", map[string]interface{}{ + return NewError(TypeError, "The type is not supported as a column.", map[string]interface{}{ "type": cf.Type, }) } @@ -371,12 +370,12 @@ func (cf *ColumnField) checkColumnType() error { func (cf *ColumnField) checkColumnName() error { s := cf.Name if s == "" { - return NewError2(TypeError, "A column name must not be empty.", map[string]interface{}{ + return NewError(TypeError, "A column name must not be empty.", map[string]interface{}{ "name": s, }) } if s[0] == '_' { - return NewError2(TypeError, "A column name must not start with '_'.", map[string]interface{}{ + return NewError(TypeError, "A column name must not start with '_'.", map[string]interface{}{ "name": s, }) } @@ -416,7 +415,7 @@ func (cf *ColumnField) checkColumn() error { // parseColumnOptions parses options of a column. func (cf *ColumnField) parseColumnOptions(options []string) error { if len(options) > 2 { - return NewError2(TypeError, "The tag must not contain more than 2 options.", map[string]interface{}{ + return NewError(TypeError, "The tag must not contain more than 2 options.", map[string]interface{}{ "name": cf.Name, "options": options, }) @@ -450,7 +449,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, NewError2(TypeError, "The struct field must have a non-empty "+columnFieldTagKey+" tag.", map[string]interface{}{ + return nil, NewError(TypeError, "The struct field must have a non-empty "+columnFieldTagKey+" tag.", map[string]interface{}{ "name": field.Name, "tag": field.Tag, }) @@ -489,7 +488,7 @@ Loop: case reflect.Struct: break Loop default: - return nil, NewError2(TypeError, "The type is not supported as a row struct.", map[string]interface{}{ + return nil, NewError(TypeError, "The type is not supported as a row struct.", map[string]interface{}{ "type": reflect.TypeOf(v).Name(), }) } @@ -519,7 +518,7 @@ Loop: cfs = append(cfs, cf) } if _, ok := cfsByName[cf.Name]; ok { - return nil, NewError2(TypeError, "The name appears more than once.", map[string]interface{}{ + return nil, NewError(TypeError, "The name appears more than once.", map[string]interface{}{ "name": cf.Name, }) } -------------- next part -------------- HTML����������������������������...다운로드