[Groonga-commit] groonga/groonga [master] show column name on cast failed.

Back to archive index

null+****@clear***** null+****@clear*****
2012年 1月 6日 (金) 15:44:59 JST


Kouhei Sutou	2012-01-06 15:44:59 +0900 (Fri, 06 Jan 2012)

  New Revision: fe81ab692ad66186fc164b76f5b8459c59cf7532

  Log:
    show column name on cast failed.

  Modified files:
    lib/db.c
    test/unit/core/test-command-load.c

  Modified: lib/db.c (+11 -6)
===================================================================
--- lib/db.c    2012-01-06 14:46:37 +0900 (d2436db)
+++ lib/db.c    2012-01-06 15:44:59 +0900 (5a9588e)
@@ -45,15 +45,20 @@
   }\
 }
 
-#define REPORT_CAST_ERROR(range, element) {\
+#define REPORT_CAST_ERROR(column, range, element) {\
   grn_obj inspected;\
+  char column_name[GRN_TABLE_MAX_KEY_SIZE];\
+  int column_name_size;\
   char range_name[GRN_TABLE_MAX_KEY_SIZE];\
   int range_name_size;\
   GRN_TEXT_INIT(&inspected, 0);\
   grn_inspect(ctx, &inspected, element);\
+  column_name_size = grn_obj_name(ctx, column, column_name,\
+                                  GRN_TABLE_MAX_KEY_SIZE);\
   range_name_size = grn_obj_name(ctx, range, range_name,\
                                  GRN_TABLE_MAX_KEY_SIZE);\
-  ERR(GRN_INVALID_ARGUMENT, "failed to cast to <%.*s>: <%.*s>",\
+  ERR(GRN_INVALID_ARGUMENT, "<%.*s>: failed to cast to <%.*s>: <%.*s>",\
+      column_name_size, column_name,\
       range_name_size, range_name,\
       GRN_TEXT_LEN(&inspected), GRN_TEXT_VALUE(&inspected));\
   GRN_OBJ_FIN(ctx, &inspected);\
@@ -5212,7 +5217,7 @@ grn_obj_set_value(grn_ctx *ctx, grn_obj *obj, grn_id id,
           if (rc) {
             grn_obj *range_obj;
             range_obj = grn_ctx_at(ctx, range);
-            REPORT_CAST_ERROR(range_obj, value);
+            REPORT_CAST_ERROR(obj, range_obj, value);
             grn_obj_unlink(ctx, range_obj);
           } else {
             value_ = &buf;
@@ -8407,7 +8412,7 @@ set_vector(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *vector)
         GRN_RECORD_INIT(&record, 0, range_id);
         if (grn_obj_cast(ctx, element, &record, GRN_TRUE)) {
           cast_failed = GRN_TRUE;
-          REPORT_CAST_ERROR(range, element);
+          REPORT_CAST_ERROR(column, range, element);
         }
         element = &record;
       }
@@ -8428,7 +8433,7 @@ set_vector(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *vector)
             GRN_OBJ_INIT(&casted_element, GRN_BULK, 0, range_id);
             if (grn_obj_cast(ctx, element, &casted_element, 1)) {
               cast_failed = GRN_TRUE;
-              REPORT_CAST_ERROR(range, element);
+              REPORT_CAST_ERROR(column, range, element);
             }
             element = &casted_element;
           }
@@ -8453,7 +8458,7 @@ set_vector(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *vector)
           GRN_OBJ_INIT(&casted_element, GRN_BULK, 0, range_id);
           if (grn_obj_cast(ctx, element, &casted_element, GRN_TRUE)) {
             cast_failed = GRN_TRUE;
-            REPORT_CAST_ERROR(range, element);
+            REPORT_CAST_ERROR(column, range, element);
           }
           element = &casted_element;
         }

  Modified: test/unit/core/test-command-load.c (+3 -2)
===================================================================
--- test/unit/core/test-command-load.c    2012-01-06 14:46:37 +0900 (69798a8)
+++ test/unit/core/test-command-load.c    2012-01-06 15:44:59 +0900 (dfbbd95)
@@ -593,7 +593,7 @@ test_invalid_int32_value(void)
   grn_test_assert_send_command_error(
     context,
     GRN_INVALID_ARGUMENT,
-    "failed to cast to <Int32>: <\"invalid number!\">",
+    "<Users.age>: failed to cast to <Int32>: <\"invalid number!\">",
     "load --table Users\n"
     "[\n"
     "{\"age\": \"invalid number!\"}\n"
@@ -670,7 +670,8 @@ test_invalid_geo_point_value(gconstpointer data)
   grn_test_assert_send_command_error(
     context,
     GRN_INVALID_ARGUMENT,
-    cut_take_printf("failed to cast to <WGS84GeoPoint>: <\"%s\">",
+    cut_take_printf("<Shops.location>: "
+                    "failed to cast to <WGS84GeoPoint>: <\"%s\">",
                     gcut_data_get_string(data, "location")),
     cut_take_printf("load --table Shops\n"
                     "[\n"




Groonga-commit メーリングリストの案内
Back to archive index