[Groonga-commit] pgroonga/pgroonga at 4709ec9 [master] Improve PGrnCheck related error messages

アーカイブの一覧に戻る

Kouhei Sutou null+****@clear*****
Thu Nov 3 23:36:23 JST 2016


Kouhei Sutou	2016-11-03 23:36:23 +0900 (Thu, 03 Nov 2016)

  New Revision: 4709ec95a6b0ef356839be6a156bf607b29a6d58
  https://github.com/pgroonga/pgroonga/commit/4709ec95a6b0ef356839be6a156bf607b29a6d58

  Message:
    Improve PGrnCheck related error messages

  Modified files:
    src/pgrn_groonga.c
    src/pgrn_groonga.h
    src/pgrn_jsonb.c
    src/pgroonga.c

  Modified: src/pgrn_groonga.c (+28 -11)
===================================================================
--- src/pgrn_groonga.c    2016-11-03 23:05:11 +0900 (0b4abd7)
+++ src/pgrn_groonga.c    2016-11-03 23:36:23 +0900 (dcfb6fc)
@@ -60,15 +60,23 @@ PGrnRCToPgErrorCode(grn_rc rc)
 }
 
 grn_bool
-PGrnCheck(const char *message)
+PGrnCheck(const char *format, ...)
 {
+#define MESSAGE_SIZE 4096
+	va_list args;
+	char message[MESSAGE_SIZE];
+
 	if (ctx->rc == GRN_SUCCESS)
 		return GRN_TRUE;
 
+	va_start(args, format);
+	grn_vsnprintf(message, MESSAGE_SIZE, format, args);
+	va_end(args);
 	ereport(ERROR,
 			(errcode(PGrnRCToPgErrorCode(ctx->rc)),
 			 errmsg("pgroonga: %s: %s", message, ctx->errbuf)));
 	return GRN_FALSE;
+#undef MESSAGE_SIZE
 }
 
 grn_obj *
@@ -238,7 +246,8 @@ PGrnCreateTableWithSize(Relation index,
 							 flags,
 							 type,
 							 NULL);
-	PGrnCheck("pgroonga: failed to create table");
+	PGrnCheck("failed to create table: <%.*s>",
+			  (int)nameSize, name);
 	if (tokenizer)
 		grn_obj_set_info(ctx, table, GRN_INFO_DEFAULT_TOKENIZER, tokenizer);
 	if (normalizer)
@@ -320,7 +329,8 @@ PGrnCreateColumnWithSize(Relation	index,
 							   path,
 							   flags,
 							   type);
-	PGrnCheck("pgroonga: failed to create column");
+	PGrnCheck("failed to create column: <%.*s>",
+			  (int)nameSize, name);
 
 	PGrnWALCreateColumn(index, table, name, nameSize, flags, type);
 
@@ -354,11 +364,21 @@ PGrnIndexColumnSetSourceIDs(Relation index,
 bool
 PGrnRemoveObject(const char *name)
 {
-	grn_obj *object = grn_ctx_get(ctx, name, strlen(name));
+	return PGrnRemoveObjectWithSize(name, strlen(name));
+}
+
+bool
+PGrnRemoveObjectWithSize(const char *name,
+						 size_t nameSize)
+{
+	grn_obj *object;
 
+	object = grn_ctx_get(ctx, name, nameSize);
 	if (object)
 	{
 		grn_obj_remove(ctx, object);
+		PGrnCheck("failed to remove: <%.*s>",
+				  (int)nameSize, name);
 		return true;
 	}
 	else
@@ -372,7 +392,7 @@ PGrnFlushObject(grn_obj *object, bool recursive)
 {
 	grn_rc rc;
 	char name[GRN_TABLE_MAX_KEY_SIZE];
-	int name_size;
+	int nameSize;
 
 	if (recursive)
 	{
@@ -385,10 +405,7 @@ PGrnFlushObject(grn_obj *object, bool recursive)
 	if (rc == GRN_SUCCESS)
 		return;
 
-	name_size = grn_obj_name(ctx, object, name, GRN_TABLE_MAX_KEY_SIZE);
-	ereport(ERROR,
-			(errcode(PGrnRCToPgErrorCode(rc)),
-			 errmsg("pgroonga: failed to flush: <%.*s>: %s",
-					name_size, name,
-					ctx->errbuf)));
+	nameSize = grn_obj_name(ctx, object, name, GRN_TABLE_MAX_KEY_SIZE);
+	PGrnCheck("failed to flush: <%.*s>",
+			  (int)nameSize, name);
 }

  Modified: src/pgrn_groonga.h (+3 -1)
===================================================================
--- src/pgrn_groonga.h    2016-11-03 23:05:11 +0900 (a7b487d)
+++ src/pgrn_groonga.h    2016-11-03 23:36:23 +0900 (1211c9c)
@@ -12,7 +12,8 @@ void PGrnInitializeGroongaInformation(void);
 const char *PGrnInspect(grn_obj *object);
 
 int PGrnRCToPgErrorCode(grn_rc rc);
-grn_bool PGrnCheck(const char *message);
+grn_bool PGrnCheck(const char *format,
+				   ...) pg_attribute_printf(1, 2);
 
 grn_obj *PGrnLookup(const char *name, int errorLevel);
 grn_obj *PGrnLookupWithSize(const char *name,
@@ -65,5 +66,6 @@ void PGrnIndexColumnSetSourceIDs(Relation index,
 								 grn_obj *sourceIDs);
 
 bool PGrnRemoveObject(const char *name);
+bool PGrnRemoveObjectWithSize(const char *name, size_t nameSize);
 
 void PGrnFlushObject(grn_obj *object, bool recursive);

  Modified: src/pgrn_jsonb.c (+7 -5)
===================================================================
--- src/pgrn_jsonb.c    2016-11-03 23:05:11 +0900 (2f52b8e)
+++ src/pgrn_jsonb.c    2016-11-03 23:36:23 +0900 (d27bfc4)
@@ -1051,19 +1051,21 @@ pgroonga_match_jsonb(PG_FUNCTION_ARGS)
 	PG_TRY();
 	{
 		GRN_EXPR_CREATE_FOR_QUERY(ctx, tmpValuesTable, filter, dummy_variable);
-		PGrnCheck("pgroonga: match_jsonb: failed to create expression object");
+		PGrnCheck("match_jsonb: failed to create expression object");
 		grn_expr_parse(ctx, filter,
 					   VARDATA_ANY(query),
 					   VARSIZE_ANY_EXHDR(query),
 					   NULL, GRN_OP_MATCH, GRN_OP_AND,
 					   GRN_EXPR_SYNTAX_SCRIPT);
-		PGrnCheck("pgroonga: match_jsonb: failed to parse query");
+		PGrnCheck("match_jsonb: failed to parse query: <%.*s>",
+				  (int)VARSIZE_ANY_EXHDR(query),
+				  VARDATA_ANY(query));
 		result = grn_table_create(ctx, NULL, 0, NULL,
 								  GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
 								  tmpValuesTable, NULL);
-		PGrnCheck("pgroonga: match_jsonb: failed to create result table");
+		PGrnCheck("match_jsonb: failed to create result table");
 		grn_table_select(ctx, tmpValuesTable, filter, result, GRN_OP_OR);
-		PGrnCheck("pgroonga: match_jsonb: failed to select");
+		PGrnCheck("match_jsonb: failed to select");
 	}
 	PG_CATCH();
 	{
@@ -1125,7 +1127,7 @@ PGrnJSONBInsertRecord(Relation index,
 	attributeName = &(attribute->attname);
 	column = PGrnLookupColumn(sourcesTable, attributeName->data, ERROR);
 	grn_obj_set_value(ctx, column, id, data->valueIDs, GRN_OBJ_SET);
-	PGrnCheck("pgroonga: failed to set column value");
+	PGrnCheck("failed to set column value: <%s>", attributeName->data);
 
 	if (walData)
 	{

  Modified: src/pgroonga.c (+6 -6)
===================================================================
--- src/pgroonga.c    2016-11-03 23:05:11 +0900 (36f746f)
+++ src/pgroonga.c    2016-11-03 23:36:23 +0900 (40591f1)
@@ -2037,7 +2037,7 @@ PGrnInsert(Relation index,
 		grn_obj_set_value(ctx, dataColumn, id, buffer, GRN_OBJ_SET);
 		PGrnWALInsertColumn(walData, dataColumn, buffer);
 		grn_obj_unlink(ctx, dataColumn);
-		if (!PGrnCheck("pgroonga: failed to set column value")) {
+		if (!PGrnCheck("failed to set column value")) {
 			continue;
 		}
 	}
@@ -2356,14 +2356,14 @@ PGrnSearchBuildConditionIn(PGrnSearchData *data,
 						PGrnLookup("in_values", ERROR),
 						GRN_OP_PUSH,
 						1);
-	PGrnCheck("pgroonga: IN: failed to push in_values()");
+	PGrnCheck("IN: failed to push in_values()");
 	grn_expr_append_obj(ctx, data->expression,
 						targetColumn,
 						GRN_OP_PUSH,
 						1);
-	PGrnCheck("pgroonga: IN: failed to push target column");
+	PGrnCheck("IN: failed to push target column");
 	grn_expr_append_op(ctx, data->expression, GRN_OP_GET_VALUE, 1);
-	PGrnCheck("pgroonga: IN: failed to push GET_VALUE");
+	PGrnCheck("IN: failed to push GET_VALUE");
 
 	for (i = 1; i <= n; i++)
 	{
@@ -2386,11 +2386,11 @@ PGrnSearchBuildConditionIn(PGrnSearchData *data,
 							  &(buffers->general),
 							  GRN_OP_PUSH,
 							  1);
-		PGrnCheck("pgroonga: IN: failed to push a value");
+		PGrnCheck("IN: failed to push a value");
 	}
 
 	grn_expr_append_op(ctx, data->expression, GRN_OP_CALL, 2 + (n - 1));
-	PGrnCheck("pgroonga: IN: failed to push CALL");
+	PGrnCheck("IN: failed to push CALL");
 
 	return true;
 }
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る