null+****@clear*****
null+****@clear*****
2010年 7月 22日 (木) 18:26:31 JST
Kouhei Sutou 2010-07-22 09:26:31 +0000 (Thu, 22 Jul 2010) New Revision: 01d5714ddb0263b2044d3c5e02e2fad301b3707a Log: report nonexistent type error on table_create. #342 Modified files: lib/proc.c test/unit/http/test-http-schema.rb Modified: lib/proc.c (+23 -4) =================================================================== --- lib/proc.c 2010-07-22 09:07:06 +0000 (de303f9) +++ lib/proc.c 2010-07-22 09:26:31 +0000 (d9e03b5) @@ -551,15 +551,34 @@ proc_table_create(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_d if (ctx->rc) { goto exit; } } if (GRN_TEXT_LEN(VAR(0))) { + grn_obj *key_type = NULL, *value_type = NULL; + if (GRN_TEXT_LEN(VAR(2)) > 0) { + key_type = grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(2)), + GRN_TEXT_LEN(VAR(2))); + if (!key_type) { + ERR(GRN_INVALID_ARGUMENT, + "key type doesn't exist: <%.*s>", + GRN_TEXT_LEN(VAR(2)), GRN_TEXT_VALUE(VAR(2))); + return NULL; + } + } + if (GRN_TEXT_LEN(VAR(3)) > 0) { + value_type = grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(3)), + GRN_TEXT_LEN(VAR(3))); + if (!value_type) { + ERR(GRN_INVALID_ARGUMENT, + "value type doesn't exist: <%.*s>", + GRN_TEXT_LEN(VAR(3)), GRN_TEXT_VALUE(VAR(3))); + return NULL; + } + } flags |= GRN_OBJ_PERSISTENT; table = grn_table_create(ctx, GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)), NULL, flags, - grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(2)), - GRN_TEXT_LEN(VAR(2))), - grn_ctx_get(ctx, GRN_TEXT_VALUE(VAR(3)), - GRN_TEXT_LEN(VAR(3)))); + key_type, + value_type); if (table) { grn_obj_set_info(ctx, table, GRN_INFO_DEFAULT_TOKENIZER, Modified: test/unit/http/test-http-schema.rb (+10 -10) =================================================================== --- test/unit/http/test-http-schema.rb 2010-07-22 09:07:06 +0000 (757c1e4) +++ test/unit/http/test-http-schema.rb 2010-07-22 09:26:31 +0000 (69689aa) @@ -339,8 +339,8 @@ class HTTPSchemaTest < Test::Unit::TestCase response = get(command_path(:table_create, :name => "users", :key_type => "nonexistent")) - assert_error_response(Result::UNKNOWN_ERROR, - "should implement error case", + assert_error_response(Result::INVALID_ARGUMENT, + "key type doesn't exist: <nonexistent>", response, :content_type => "application/json") @@ -372,8 +372,8 @@ class HTTPSchemaTest < Test::Unit::TestCase response = get(command_path(:table_create, :name => "users", :value_type => "nonexistent")) - assert_error_response(Result::UNKNOWN_ERROR, - "should implement error case", + assert_error_response(Result::INVALID_ARGUMENT, + "value type doesn't exist: <nonexistent>", response, :content_type => "application/json") @@ -460,8 +460,8 @@ class HTTPSchemaTest < Test::Unit::TestCase :name => "users", :flags => Table::PAT_KEY, :key_type => "nonexistent")) - assert_error_response(Result::UNKNOWN_ERROR, - "should implement error case", + assert_error_response(Result::INVALID_ARGUMENT, + "key type doesn't exist: <nonexistent>", response, :content_type => "application/json") @@ -497,8 +497,8 @@ class HTTPSchemaTest < Test::Unit::TestCase :name => "users", :flags => Table::PAT_KEY, :value_type => "nonexistent")) - assert_error_response(Result::UNKNOWN_ERROR, - "should implement error case", + assert_error_response(Result::INVALID_ARGUMENT, + "value type doesn't exist: <nonexistent>", response, :content_type => "application/json") @@ -588,8 +588,8 @@ class HTTPSchemaTest < Test::Unit::TestCase :name => "users", :flags => Table::NO_KEY, :value_type => "nonexistent")) - assert_error_response(Result::UNKNOWN_ERROR, - "value type doesn't exist", + assert_error_response(Result::INVALID_ARGUMENT, + "value type doesn't exist: <nonexistent>", response, :content_type => "application/json")