Navigation Menu

Skip to content

Commit

Permalink
table get: add "[table][get] " prefix to error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 14, 2012
1 parent 1172487 commit 9f3a441
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
22 changes: 12 additions & 10 deletions plugins/table/table.c
Expand Up @@ -442,14 +442,14 @@ command_get_resolve_parameters(grn_ctx *ctx, grn_user_data *user_data,
table_text = GRN_TEXT_VALUE(VAR(0));
table_length = GRN_TEXT_LEN(VAR(0));
if (table_length == 0) {
ERR(GRN_INVALID_ARGUMENT, "table isn't specified");
ERR(GRN_INVALID_ARGUMENT, "[table][get] table isn't specified");
return ctx->rc;
}

*table = grn_ctx_get(ctx, table_text, table_length);
if (!*table) {
ERR(GRN_INVALID_ARGUMENT,
"table doesn't exist: <%.*s>", table_length, table_text);
"[table][get] table doesn't exist: <%.*s>", table_length, table_text);
return ctx->rc;
}

Expand All @@ -461,7 +461,8 @@ command_get_resolve_parameters(grn_ctx *ctx, grn_user_data *user_data,
case GRN_TABLE_NO_KEY:
if (key_length) {
ERR(GRN_INVALID_ARGUMENT,
"should not specify key for NO_KEY table: <%.*s>: table: <%.*s>",
"[table][get] should not specify key for NO_KEY table: <%.*s>: "
"table: <%.*s>",
key_length, key_text,
table_length, table_text);
return ctx->rc;
Expand All @@ -471,13 +472,13 @@ command_get_resolve_parameters(grn_ctx *ctx, grn_user_data *user_data,
*id = grn_atoi(id_text, id_text + id_length, &rest);
if (rest == id_text) {
ERR(GRN_INVALID_ARGUMENT,
"ID should be a number: <%.*s>: table: <%.*s>",
"[table][get] ID should be a number: <%.*s>: table: <%.*s>",
id_length, id_text,
table_length, table_text);
}
} else {
ERR(GRN_INVALID_ARGUMENT,
"ID isn't specified: table: <%.*s>",
"[table][get] ID isn't specified: table: <%.*s>",
table_length, table_text);
}
break;
Expand All @@ -487,7 +488,7 @@ command_get_resolve_parameters(grn_ctx *ctx, grn_user_data *user_data,
case GRN_TABLE_VIEW:
if (key_length && id_length) {
ERR(GRN_INVALID_ARGUMENT,
"should not specify both key and ID: "
"[table][get] should not specify both key and ID: "
"key: <%.*s>: ID: <%.*s>: table: <%.*s>",
key_length, key_text,
id_length, id_text,
Expand All @@ -498,7 +499,7 @@ command_get_resolve_parameters(grn_ctx *ctx, grn_user_data *user_data,
*id = grn_table_get(ctx, *table, key_text, key_length);
if (!*id) {
ERR(GRN_INVALID_ARGUMENT,
"nonexistent key: <%.*s>: table: <%.*s>",
"[table][get] nonexistent key: <%.*s>: table: <%.*s>",
key_length, key_text,
table_length, table_text);
}
Expand All @@ -508,19 +509,20 @@ command_get_resolve_parameters(grn_ctx *ctx, grn_user_data *user_data,
*id = grn_atoi(id_text, id_text + id_length, &rest);
if (rest == id_text) {
ERR(GRN_INVALID_ARGUMENT,
"ID should be a number: <%.*s>: table: <%.*s>",
"[table][get] ID should be a number: <%.*s>: table: <%.*s>",
id_length, id_text,
table_length, table_text);
}
} else {
ERR(GRN_INVALID_ARGUMENT,
"key nor ID isn't specified: table: <%.*s>",
"[table][get] key nor ID isn't specified: table: <%.*s>",
table_length, table_text);
}
}
break;
default:
ERR(GRN_INVALID_ARGUMENT, "not a table: <%.*s>", table_length, table_text);
ERR(GRN_INVALID_ARGUMENT,
"[table][get] not a table: <%.*s>", table_length, table_text);
break;
}

Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 25 additions & 0 deletions test/function/suite/table/get/not_exist.expected
@@ -0,0 +1,25 @@
register table/table
[[0,0.0,0.0],true]
table_create Diaries TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
column_create Diaries title COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
column_create Diaries tags COLUMN_VECTOR ShortText
[[0,0.0,0.0],true]
load --table Diaries
[
{"_key":"2012-08-14", "title": "'get' command is moved!", "tags": ["groonga", "development"]},
]
[[0,0.0,0.0],1]
get Diaries 'nonexistent'
[
[
[
-22,
0.0,
0.0
],
"[table][get] nonexistent key: <nonexistent>: table: <Diaries>"
]
]
#|e| [table][get] nonexistent key: <nonexistent>: table: <Diaries>
10 changes: 10 additions & 0 deletions test/function/suite/table/get/not_exist.test
@@ -0,0 +1,10 @@
register table/table
table_create Diaries TABLE_PAT_KEY ShortText
column_create Diaries title COLUMN_SCALAR ShortText
column_create Diaries tags COLUMN_VECTOR ShortText

load --table Diaries
[
{"_key":"2012-08-14", "title": "'get' command is moved!", "tags": ["groonga", "development"]},
]
get Diaries 'nonexistent'

0 comments on commit 9f3a441

Please sign in to comment.