[Groonga-commit] groonga/groonga at 83f820a [master] normalize: improve error messages

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jun 5 22:52:32 JST 2014


Kouhei Sutou	2014-06-05 22:52:32 +0900 (Thu, 05 Jun 2014)

  New Revision: 83f820aabcdd9088d24e429800be8382b9eabe87
  https://github.com/groonga/groonga/commit/83f820aabcdd9088d24e429800be8382b9eabe87

  Message:
    normalize: improve error messages

  Added files:
    test/command/suite/normalize/invalid/normalizer/invalid.expected
    test/command/suite/normalize/invalid/normalizer/invalid.test
    test/command/suite/normalize/invalid/normalizer/nonexistent.expected
    test/command/suite/normalize/invalid/normalizer/nonexistent.test
  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+29 -4)
===================================================================
--- lib/proc.c    2014-06-05 21:44:13 +0900 (e51be05)
+++ lib/proc.c    2014-06-05 22:52:32 +0900 (3f86c7f)
@@ -2944,6 +2944,20 @@ parse_normalize_flags(grn_ctx *ctx, grn_obj *flag_names)
   return flags;
 }
 
+static grn_bool
+is_normalizer(grn_ctx *ctx, grn_obj *object)
+{
+  if (object->header.type != GRN_PROC) {
+    return GRN_FALSE;
+  }
+
+  if (grn_proc_get_type(ctx, object) != GRN_PROC_NORMALIZER) {
+    return GRN_FALSE;
+  }
+
+  return GRN_TRUE;
+}
+
 static const char *
 char_type_name(grn_char_type type)
 {
@@ -3006,17 +3020,28 @@ proc_normalize(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data
     normalizer = grn_ctx_get(ctx,
                              GRN_TEXT_VALUE(normalizer_name),
                              GRN_TEXT_LEN(normalizer_name));
-    if (!normalizer ||
-        normalizer->header.type != GRN_PROC ||
-        grn_proc_get_type(ctx, normalizer) != GRN_PROC_NORMALIZER) {
+    if (!normalizer) {
       ERR(GRN_INVALID_ARGUMENT,
-          "unknown normalizer: <%.*s>",
+          "[normalize] nonexistent normalizer: <%.*s>",
           (int)GRN_TEXT_LEN(normalizer_name),
           GRN_TEXT_VALUE(normalizer_name));
       GRN_OUTPUT_CSTR("");
       return NULL;
     }
 
+    if (!is_normalizer(ctx, normalizer)) {
+      grn_obj inspected;
+      GRN_TEXT_INIT(&inspected, 0);
+      grn_inspect(ctx, &inspected, normalizer);
+      ERR(GRN_INVALID_ARGUMENT,
+          "[normalize] not normalizer: %.*s",
+          (int)GRN_TEXT_LEN(&inspected),
+          GRN_TEXT_VALUE(&inspected));
+      GRN_OBJ_FIN(ctx, &inspected);
+      GRN_OUTPUT_CSTR("");
+      return NULL;
+    }
+
     grn_string = grn_string_open(ctx,
                                  GRN_TEXT_VALUE(string), GRN_TEXT_LEN(string),
                                  normalizer, flags);

  Added: test/command/suite/normalize/invalid/normalizer/invalid.expected (+13 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/normalize/invalid/normalizer/invalid.expected    2014-06-05 22:52:32 +0900 (18e9da6)
@@ -0,0 +1,13 @@
+normalize TokenBigram "aBcDe"
+[
+  [
+    [
+      -22,
+      0.0,
+      0.0
+    ],
+    "[normalize] not normalizer: #<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>"
+  ],
+  ""
+]
+#|e| [normalize] not normalizer: #<proc:tokenizer TokenBigram arguments:[$1, $2, $3]>

  Added: test/command/suite/normalize/invalid/normalizer/invalid.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/normalize/invalid/normalizer/invalid.test    2014-06-05 22:52:32 +0900 (c18bdc0)
@@ -0,0 +1 @@
+normalize TokenBigram "aBcDe"

  Added: test/command/suite/normalize/invalid/normalizer/nonexistent.expected (+3 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/normalize/invalid/normalizer/nonexistent.expected    2014-06-05 22:52:32 +0900 (41db233)
@@ -0,0 +1,3 @@
+normalize Nonexistent "aBcDe"
+[[[-22,0.0,0.0],"[normalize] nonexistent normalizer: <Nonexistent>"],""]
+#|e| [normalize] nonexistent normalizer: <Nonexistent>

  Added: test/command/suite/normalize/invalid/normalizer/nonexistent.test (+1 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/normalize/invalid/normalizer/nonexistent.test    2014-06-05 22:52:32 +0900 (215eb67)
@@ -0,0 +1 @@
+normalize Nonexistent "aBcDe"
-------------- next part --------------
HTML����������������������������...
Download 



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