[Groonga-commit] groonga/groonga at 409ce25 [master] Improve error message

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Aug 24 11:00:40 JST 2016


Kouhei Sutou	2016-08-24 11:00:40 +0900 (Wed, 24 Aug 2016)

  New Revision: 409ce25469d65741abf08694e156fb54f5d35956
  https://github.com/groonga/groonga/commit/409ce25469d65741abf08694e156fb54f5d35956

  Message:
    Improve error message

  Modified files:
    lib/db.c
    test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected
    test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected
    test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected
    test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected

  Modified: lib/db.c (+42 -56)
===================================================================
--- lib/db.c    2016-08-23 20:14:22 +0900 (505b4a3)
+++ lib/db.c    2016-08-24 11:00:40 +0900 (1cdea6b)
@@ -8369,22 +8369,31 @@ grn_obj_spec_save(grn_ctx *ctx, grn_db_obj *obj)
 }
 
 inline static void
-grn_obj_set_info_source_invalid_source_type_error(grn_ctx *ctx,
-                                                  const char *message,
-                                                  grn_obj *source,
-                                                  grn_id source_type_id,
-                                                  grn_obj *column,
-                                                  grn_obj *expected_type)
-{
-  char source_name[GRN_TABLE_MAX_KEY_SIZE];
-  int source_name_size;
-  grn_obj *source_type;
-  char source_type_name[GRN_TABLE_MAX_KEY_SIZE];
-  int source_type_name_size;
-  char column_name[GRN_TABLE_MAX_KEY_SIZE];
-  int column_name_size;
+grn_obj_set_info_source_invalid_lexicon_error(grn_ctx *ctx,
+                                              const char *message,
+                                              grn_obj *actual_type,
+                                              grn_obj *expected_type,
+                                              grn_obj *index_column,
+                                              grn_obj *source)
+{
+  char actual_type_name[GRN_TABLE_MAX_KEY_SIZE];
+  int actual_type_name_size;
   char expected_type_name[GRN_TABLE_MAX_KEY_SIZE];
   int expected_type_name_size;
+  char index_column_name[GRN_TABLE_MAX_KEY_SIZE];
+  int index_column_name_size;
+  char source_name[GRN_TABLE_MAX_KEY_SIZE];
+  int source_name_size;
+
+  actual_type_name_size = grn_obj_name(ctx, actual_type,
+                                       actual_type_name,
+                                       GRN_TABLE_MAX_KEY_SIZE);
+  expected_type_name_size = grn_obj_name(ctx, expected_type,
+                                         expected_type_name,
+                                         GRN_TABLE_MAX_KEY_SIZE);
+  index_column_name_size = grn_obj_name(ctx, index_column,
+                                        index_column_name,
+                                        GRN_TABLE_MAX_KEY_SIZE);
 
   source_name_size = grn_obj_name(ctx, source,
                                   source_name, GRN_TABLE_MAX_KEY_SIZE);
@@ -8397,35 +8406,16 @@ grn_obj_set_info_source_invalid_source_type_error(grn_ctx *ctx,
     source_name_size = strlen(source_name);
   }
 
-  source_type = grn_ctx_at(ctx, source_type_id);
-  if (source_type) {
-    source_type_name_size = grn_obj_name(ctx, source_type,
-                                         source_type_name,
-                                         GRN_TABLE_MAX_KEY_SIZE);
-    grn_obj_unlink(ctx, source_type);
-  } else {
-    grn_strncpy(source_type_name,
-                GRN_TABLE_MAX_KEY_SIZE,
-                "(nil)",
-                GRN_TABLE_MAX_KEY_SIZE);
-    source_type_name_size = strlen(source_type_name);
-  }
-
-  column_name_size = grn_obj_name(ctx, column,
-                                  column_name, GRN_TABLE_MAX_KEY_SIZE);
-  expected_type_name_size = grn_obj_name(ctx, expected_type,
-                                         expected_type_name,
-                                         GRN_TABLE_MAX_KEY_SIZE);
   ERR(GRN_INVALID_ARGUMENT,
       "[column][index][source] %s: "
-      "source:<%.*s(%.*s)> "
-      "expected:<%.*s> "
-      "index:<%.*s>",
+      "<%.*s> -> <%.*s>: "
+      "index-column:<%.*s>"
+      "source:<%.*s> ",
       message,
-      source_name_size, source_name,
-      source_type_name_size, source_type_name,
+      actual_type_name_size, actual_type_name,
       expected_type_name_size, expected_type_name,
-      column_name_size, column_name);
+      index_column_name_size, index_column_name,
+      source_name_size, source_name);
 }
 
 inline static grn_rc
@@ -8477,7 +8467,7 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
     grn_id source_id = source_ids[i];
     grn_obj *source;
     grn_id source_type_id;
-    grn_id source_type_is_table;
+    grn_obj *source_type;
 
     source = grn_ctx_at(ctx, source_id);
     if (!source) {
@@ -8488,31 +8478,27 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)
     } else {
       source_type_id = DB_OBJ(source)->range;
     }
-    {
-      grn_obj *source_type;
-      source_type = grn_ctx_at(ctx, source_type_id);
-      source_type_is_table = grn_obj_is_table(ctx, source_type);
-    }
+    source_type = grn_ctx_at(ctx, source_type_id);
     if (!lexicon_have_tokenizer) {
-      if (source_type_is_table) {
+      if (grn_obj_is_table(ctx, source_type)) {
         if (lexicon_id != source_type_id) {
-          grn_obj_set_info_source_invalid_source_type_error(
+          grn_obj_set_info_source_invalid_lexicon_error(
             ctx,
-            "source type must equal to index table",
-            source,
-            source_type_id,
+            "index table must equal to source type",
+            lexicon,
+            source_type,
             obj,
-            lexicon);
+            source);
         }
       } else {
         if (lexicon_domain_id != source_type_id) {
-          grn_obj_set_info_source_invalid_source_type_error(
+          grn_obj_set_info_source_invalid_lexicon_error(
             ctx,
-            "source type must equal to index table's key",
-            source,
-            source_type_id,
+            "index table's key must equal source type",
+            lexicon_domain,
+            source_type,
             obj,
-            lexicon_domain);
+            source);
         }
       }
     }

  Modified: test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected (+2 -2)
===================================================================
--- test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected    2016-08-23 20:14:22 +0900 (91f985d)
+++ test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected    2016-08-24 11:00:40 +0900 (0353265)
@@ -14,8 +14,8 @@ column_create TagsIndex sites_tags COLUMN_INDEX Sites tags
       0.0,
       0.0
     ],
-    "[column][index][source] source type must equal to index table's key: source:<Sites.tags(ShortText)> expected:<Tags> index:<Tags"
+    "[column][index][source] index table's key must equal source type: <Tags> -> <ShortText>: index-column:<TagsIndex.sites_tags>sou"
   ],
   false
 ]
-#|e| [column][index][source] source type must equal to index table's key: source:<Sites.tags(ShortText)> expected:<Tags> index:<TagsIndex.sites_tags>
+#|e| [column][index][source] index table's key must equal source type: <Tags> -> <ShortText>: index-column:<TagsIndex.sites_tags>source:<Sites.tags> 

  Modified: test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected (+2 -2)
===================================================================
--- test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected    2016-08-23 20:14:22 +0900 (ffbe9d5)
+++ test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected    2016-08-24 11:00:40 +0900 (71efe3e)
@@ -12,8 +12,8 @@ column_create TagsIndex sites_tags COLUMN_INDEX TagPriorities _key
       0.0,
       0.0
     ],
-    "[column][index][source] source type must equal to index table's key: source:<TagPriorities._key(ShortText)> expected:<Tags> ind"
+    "[column][index][source] index table's key must equal source type: <Tags> -> <ShortText>: index-column:<TagsIndex.sites_tags>sou"
   ],
   false
 ]
-#|e| [column][index][source] source type must equal to index table's key: source:<TagPriorities._key(ShortText)> expected:<Tags> index:<TagsIndex.sites_tags>
+#|e| [column][index][source] index table's key must equal source type: <Tags> -> <ShortText>: index-column:<TagsIndex.sites_tags>source:<TagPriorities._key> 

  Modified: test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected (+2 -2)
===================================================================
--- test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected    2016-08-23 20:14:22 +0900 (4b0676d)
+++ test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected    2016-08-24 11:00:40 +0900 (312e843)
@@ -14,8 +14,8 @@ column_create TagsIndex sites_tags COLUMN_INDEX Sites tags
       0.0,
       0.0
     ],
-    "[column][index][source] source type must equal to index table: source:<Sites.tags(Tags)> expected:<TagsIndex> index:<TagsIndex."
+    "[column][index][source] index table must equal to source type: <TagsIndex> -> <Tags>: index-column:<TagsIndex.sites_tags>source"
   ],
   false
 ]
-#|e| [column][index][source] source type must equal to index table: source:<Sites.tags(Tags)> expected:<TagsIndex> index:<TagsIndex.sites_tags>
+#|e| [column][index][source] index table must equal to source type: <TagsIndex> -> <Tags>: index-column:<TagsIndex.sites_tags>source:<Sites.tags> 

  Modified: test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected (+2 -2)
===================================================================
--- test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected    2016-08-23 20:14:22 +0900 (def34b8)
+++ test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected    2016-08-24 11:00:40 +0900 (7052458)
@@ -12,8 +12,8 @@ column_create TagsIndex sites_tags COLUMN_INDEX TagPriorities _key
       0.0,
       0.0
     ],
-    "[column][index][source] source type must equal to index table: source:<TagPriorities._key(Tags)> expected:<TagsIndex> index:<Ta"
+    "[column][index][source] index table must equal to source type: <TagsIndex> -> <Tags>: index-column:<TagsIndex.sites_tags>source"
   ],
   false
 ]
-#|e| [column][index][source] source type must equal to index table: source:<TagPriorities._key(Tags)> expected:<TagsIndex> index:<TagsIndex.sites_tags>
+#|e| [column][index][source] index table must equal to source type: <TagsIndex> -> <Tags>: index-column:<TagsIndex.sites_tags>source:<TagPriorities._key> 
-------------- next part --------------
HTML����������������������������...
Download 



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