[Groonga-commit] groonga/groonga [master] [ql][column_create] improve error message on nonexistent table name error.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 6月 3日 (金) 18:49:32 JST


Kouhei Sutou	2011-06-03 09:49:32 +0000 (Fri, 03 Jun 2011)

  New Revision: 5a09c92627fe435420f054c338bb7740115f3631

  Log:
    [ql][column_create] improve error message on nonexistent table name error.
    
    refs #952

  Modified files:
    lib/db.c
    lib/proc.c
    test/unit/core/test-command-column-create.c

  Modified: lib/db.c (+5 -1)
===================================================================
--- lib/db.c    2011-06-03 09:34:11 +0000 (fd5c2df)
+++ lib/db.c    2011-06-03 09:49:32 +0000 (b7ad6c3)
@@ -2802,7 +2802,11 @@ grn_column_create(grn_ctx *ctx, grn_obj *table,
   char fullname[GRN_PAT_MAX_KEY_SIZE];
   char buffer[PATH_MAX];
   GRN_API_ENTER;
-  if (!table || !type || !name || !name_size) {
+  if (!table) {
+    ERR(GRN_INVALID_ARGUMENT, "[column][create]: table is missing");
+    goto exit;
+  }
+  if (!type || !name || !name_size) {
     ERR(GRN_INVALID_ARGUMENT, "missing type or name");
     goto exit;
   }

  Modified: lib/proc.c (+7 -2)
===================================================================
--- lib/proc.c    2011-06-03 09:34:11 +0000 (c40af6f)
+++ lib/proc.c    2011-06-03 09:49:32 +0000 (7f491c8)
@@ -647,8 +647,13 @@ proc_column_create(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_
                                           GRN_BULK_CURR(VAR(2)));
     if (ctx->rc) { goto exit; }
   }
-  table = grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(0)),
-                      GRN_TEXT_LEN(VAR(0)));
+  table = grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)));
+  if (!table) {
+    ERR(GRN_INVALID_ARGUMENT,
+        "[column][create]: table doesn't exist: <%.*s>",
+        GRN_TEXT_LEN(VAR(0)), GRN_TEXT_VALUE(VAR(0))) ;
+    goto exit;
+  }
   type = grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(3)),
                      GRN_TEXT_LEN(VAR(3)));
   if (GRN_TEXT_LEN(VAR(1))) { flags |= GRN_OBJ_PERSISTENT; }

  Modified: test/unit/core/test-command-column-create.c (+11 -0)
===================================================================
--- test/unit/core/test-command-column-create.c    2011-06-03 09:34:11 +0000 (59099e5)
+++ test/unit/core/test-command-column-create.c    2011-06-03 09:49:32 +0000 (bed136d)
@@ -24,6 +24,7 @@
 #include <str.h>
 
 void test_invalid_name(void);
+void test_nonexistent_table(void);
 
 static gchar *tmp_directory;
 static const gchar *database_path;
@@ -87,3 +88,13 @@ test_invalid_name(void)
     "and contains only 0-9, A-Z, a-z, or _: <_name>",
     "column_create Users _name COLUMN_SCALAR ShortText");
 }
+
+void
+test_nonexistent_table(void)
+{
+  grn_test_assert_send_command_error(
+    context,
+    GRN_INVALID_ARGUMENT,
+    "[column][create]: table doesn't exist: <Users>",
+    "column_create Users name COLUMN_SCALAR ShortText");
+}




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