[Groonga-commit] groonga/grngo at 3c09a31 [master] Add newGrnError() which returns an error from grn_rc and grn_ctx.

Back to archive index

susumu.yata null+****@clear*****
Thu Jul 9 13:14:50 JST 2015


susumu.yata	2015-07-09 13:14:50 +0900 (Thu, 09 Jul 2015)

  New Revision: 3c09a31b2417a89bfb7848501ccd9aeab0f47dde
  https://github.com/groonga/grngo/commit/3c09a31b2417a89bfb7848501ccd9aeab0f47dde

  Message:
    Add newGrnError() which returns an error from grn_rc and grn_ctx.
    
    GitHub: #12

  Modified files:
    grngo.go

  Modified: grngo.go (+25 -0)
===================================================================
--- grngo.go    2015-07-09 13:13:39 +0900 (b90d7ec)
+++ grngo.go    2015-07-09 13:14:50 +0900 (265b67a)
@@ -177,6 +177,31 @@ func (rc C.grn_rc) String() string {
 	}
 }
 
+// newGrnError returns an error related to a Groonga or Grngo operation.
+func newGrnError(opName string, rc *C.grn_rc, ctx *C.grn_ctx) error {
+	switch {
+	case rc == nil:
+		if ctx == nil {
+			return fmt.Errorf("%s failed", opName)
+		}
+		if ctx.rc == C.GRN_SUCCESS {
+			return fmt.Errorf("%s failed: ctx.rc = %s (%d)", opName, ctx.rc, ctx.rc)
+		}
+		msg := C.GoString(&ctx.errbuf[0])
+		return fmt.Errorf("%s failed: ctx.rc = %s (%d), ctx.errbuf = %s",
+			opName, ctx.rc, ctx.rc, msg)
+	case ctx == nil:
+		return fmt.Errorf("%s failed: rc = %s (%d)", opName, *rc, *rc)
+	case ctx.rc == C.GRN_SUCCESS:
+		return fmt.Errorf("%s failed: rc = %s (%d), ctx.rc = %s (%d)",
+			opName, *rc, *rc, ctx.rc, ctx.rc)
+	default:
+		msg := C.GoString(&ctx.errbuf[0])
+		return fmt.Errorf("%s failed: rc = %s (%d), ctx.rc = %s (%d), ctx.errbuf = %s",
+			opName, *rc, *rc, ctx.rc, ctx.rc, msg)
+	}
+}
+
 // newInvalidKeyTypeError returns an error for data type conflict.
 func newInvalidKeyTypeError(expected, actual DataType) error {
 	return fmt.Errorf("invalid data type: expected = %s, actual = %s", expected, actual)
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index