[Groonga-commit] groonga/grnci at afd372a [master] Remove UnknownError and add Input/Output/UnexpectedError.

Zurück zum Archiv-Index

Susumu Yata null+****@clear*****
Tue Aug 1 16:55:54 JST 2017


Susumu Yata	2017-08-01 16:55:54 +0900 (Tue, 01 Aug 2017)

  New Revision: afd372a2e983779e00560243f299d85e0af8aa13
  https://github.com/groonga/grnci/commit/afd372a2e983779e00560243f299d85e0af8aa13

  Message:
    Remove UnknownError and add Input/Output/UnexpectedError.

  Added files:
    v2/cpu.out
    v2/v2.test
  Modified files:
    v2/command.go
    v2/db.go
    v2/error.go
    v2/error_test.go
    v2/libgrn/libgrn.go

  Modified: v2/command.go (+1 -1)
===================================================================
--- v2/command.go    2017-07-31 12:12:27 +0900 (1bfe665)
+++ v2/command.go    2017-08-01 16:55:54 +0900 (a8b5890)
@@ -1053,7 +1053,7 @@ func (cr *CommandReader) fill() error {
 	if err != nil {
 		cr.err = err
 		if err != io.EOF {
-			cr.err = NewError(CommandError, map[string]interface{}{
+			cr.err = NewError(InputError, map[string]interface{}{
 				"error": err.Error(),
 			})
 		}

  Added: v2/cpu.out (+0 -0) 100644
===================================================================
(Binary files differ)

  Modified: v2/db.go (+2 -2)
===================================================================
--- v2/db.go    2017-07-31 12:12:27 +0900 (a261e84)
+++ v2/db.go    2017-08-01 16:55:54 +0900 (c858436)
@@ -1359,14 +1359,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 = NewError(UnknownError, map[string]interface{}{
+						e = NewError(OutputError, map[string]interface{}{
 							"error": e.Error(),
 						})
 					}
 					err = e
 				}
 				if _, e := w.Write([]byte("\n")); e != nil && err == nil {
-					err = NewError(UnknownError, map[string]interface{}{
+					err = NewError(OutputError, map[string]interface{}{
 						"error": e.Error(),
 					})
 				}

  Modified: v2/error.go (+21 -10)
===================================================================
--- v2/error.go    2017-07-31 12:12:27 +0900 (2109072)
+++ v2/error.go    2017-08-01 16:55:54 +0900 (f60a860)
@@ -15,10 +15,13 @@ const (
 	OperationError
 	ResponseError
 	TypeError
+	IOError
 	NetworkError
+	InputError
+	OutputError
 	HTTPError
 	GroongaError
-	UnknownError
+	UnexpectedError
 )
 
 // Name returns the name of the error code such as "AddressError".
@@ -36,12 +39,16 @@ func (ec ErrorCode) Name() string {
 		return "TypeError"
 	case NetworkError:
 		return "NetworkError"
+	case InputError:
+		return "InputError"
+	case OutputError:
+		return "OutputError"
 	case HTTPError:
 		return "HTTPError"
 	case GroongaError:
 		return "GroongaError"
-	case UnknownError:
-		return "UnknownError"
+	case UnexpectedError:
+		return "UnexpectedError"
 	default:
 		return "N/A"
 	}
@@ -49,16 +56,18 @@ func (ec ErrorCode) Name() string {
 
 // String returns a string that consists of the error code and its name.
 func (ec ErrorCode) String() string {
-	return strconv.Itoa(int(ec)) + " " + ec.Name()
+	return ec.Name() + " (" + strconv.Itoa(int(ec)) + ")"
 }
 
 // MarshalJSON returns the JSON-encoded error code.
 func (ec ErrorCode) MarshalJSON() ([]byte, error) {
 	buf := make([]byte, 0, 24)
 	buf = append(buf, '"')
-	buf = strconv.AppendInt(buf, int64(ec), 10)
-	buf = append(buf, ' ')
 	buf = append(buf, ec.Name()...)
+	buf = append(buf, ' ')
+	buf = append(buf, '(')
+	buf = strconv.AppendInt(buf, int64(ec), 10)
+	buf = append(buf, ')')
 	buf = append(buf, '"')
 	return buf, nil
 }
@@ -238,16 +247,18 @@ func (rc ResultCode) Name() string {
 
 // String returns a string that consists of the result code and its name.
 func (rc ResultCode) String() string {
-	return strconv.Itoa(int(rc)) + " " + rc.Name()
+	return rc.Name() + " (" + strconv.Itoa(int(rc)) + ")"
 }
 
 // MarshalJSON returns the JSON-encoded error code.
 func (rc ResultCode) MarshalJSON() ([]byte, error) {
 	buf := make([]byte, 0, 48)
 	buf = append(buf, '"')
-	buf = strconv.AppendInt(buf, int64(rc), 10)
-	buf = append(buf, ' ')
 	buf = append(buf, rc.Name()...)
+	buf = append(buf, ' ')
+	buf = append(buf, '(')
+	buf = strconv.AppendInt(buf, int64(rc), 10)
+	buf = append(buf, ')')
 	buf = append(buf, '"')
 	return buf, nil
 }
@@ -292,7 +303,7 @@ func EnhanceError(err error, data map[string]interface{}) *Error {
 		}
 		return e
 	}
-	e := NewError(UnknownError, data)
+	e := NewError(UnexpectedError, data)
 	if _, ok := e.Data["error"]; !ok {
 		data["error"] = err.Error()
 	}

  Modified: v2/error_test.go (+3 -1)
===================================================================
--- v2/error_test.go    2017-07-31 12:12:27 +0900 (b1228e0)
+++ v2/error_test.go    2017-08-01 16:55:54 +0900 (6eb182a)
@@ -1,6 +1,8 @@
 package grnci
 
-import "testing"
+import (
+	"testing"
+)
 
 func TestNewError(t *testing.T) {
 	data := map[string]interface{}{

  Modified: v2/libgrn/libgrn.go (+3 -3)
===================================================================
--- v2/libgrn/libgrn.go    2017-07-31 12:12:27 +0900 (5946da3)
+++ v2/libgrn/libgrn.go    2017-08-01 16:55:54 +0900 (f3f673f)
@@ -100,7 +100,7 @@ func newGrnCtx() (*grnCtx, error) {
 	ctx := C.grn_ctx_open(C.int(0))
 	if ctx == nil {
 		Fin()
-		return nil, grnci.NewError(grnci.UnknownError, map[string]interface{}{
+		return nil, grnci.NewError(grnci.UnexpectedError, map[string]interface{}{
 			"method": "C.grn_ctx_open",
 		})
 	}
@@ -193,7 +193,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.NewError(grnci.UnknownError, map[string]interface{}{
+		return nil, grnci.NewError(grnci.UnexpectedError, map[string]interface{}{
 			"method": "C.grn_db_create",
 		})
 	}
@@ -212,7 +212,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.NewError(grnci.UnknownError, map[string]interface{}{
+		return nil, grnci.NewError(grnci.UnexpectedError, map[string]interface{}{
 			"method": "C.grn_db_open",
 		})
 	}

  Added: v2/v2.test (+0 -0) 100755
===================================================================
(Binary files differ)
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index