From 38d4d994f8fdb6af759b8e8530e3fff0a7374d61 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Mon, 6 Jan 2014 22:49:41 +0400 Subject: [PATCH] [msgpack] Reorder error codes and remove reserved dated error codes. Change box.error to push error codes without error flags. --- src/errcode.h | 111 ++++++++++++++++----------------------- src/lua/init.cc | 2 +- test/box/lua_misc.result | 82 ++++++++++++++--------------- test/lib/sql_ast.py | 99 +++++++++++++++------------------- 4 files changed, 127 insertions(+), 167 deletions(-) diff --git a/src/errcode.h b/src/errcode.h index 2082ea0b34..bf4faf729b 100644 --- a/src/errcode.h +++ b/src/errcode.h @@ -41,8 +41,7 @@ struct errcode_record { enum { TNT_ERRMSG_MAX = 512 }; /* - * To add a new error code to Tarantool, extend this array. Please - * try to reuse empty slots (ER_UNUSED*), if there are any left. + * To add a new error code to Tarantool, extend this array. * * !IMPORTANT! Currently you need to manually update the user * guide (doc/user/errcode.xml) with each added error code. @@ -51,65 +50,46 @@ enum { TNT_ERRMSG_MAX = 512 }; #define ERROR_CODES(_) \ /* 0 */_(ER_OK, 0, "OK") \ - /* 1 */_(ER_NONMASTER, 2, "Can't modify data on a replication slave. My master is: %s") \ - /* 2 */_(ER_ILLEGAL_PARAMS, 2, "Illegal parameters, %s") \ - /* 3 */_(ER_SECONDARY, 2, "Can't modify data upon a request on the secondary port.") \ - /* 4 */_(ER_TUPLE_IS_RO, 1, "Tuple is marked as read-only") \ - /* 5 */_(ER_INDEX_TYPE, 2, "Unsupported index type supplied for index %u in space %u") \ - /* 6 */_(ER_SPACE_EXISTS, 2, "Space %u already exists") \ - /* 7 */_(ER_MEMORY_ISSUE, 1, "Failed to allocate %u bytes in %s for %s") \ - /* 8 */_(ER_CREATE_SPACE, 2, "Failed to create space %u: %s") \ - /* 9 */_(ER_INJECTION, 2, "Error injection '%s'") \ - /* 10 */_(ER_UNSUPPORTED, 2, "%s does not support %s") \ - /* silverproxy error codes */ \ - /* 11 */_(ER_RESERVED11, 0, "Reserved11") \ - /* 12 */_(ER_RESERVED12, 0, "Reserved12") \ - /* 13 */_(ER_RESERVED13, 0, "Reserved13") \ - /* 14 */_(ER_RESERVED14, 0, "Reserved14") \ - /* 15 */_(ER_RESERVED15, 0, "Reserved15") \ - /* 16 */_(ER_RESERVED16, 0, "Reserved16") \ - /* 17 */_(ER_RESERVED17, 0, "Reserved17") \ - /* 18 */_(ER_RESERVED18, 0, "Reserved18") \ - /* 19 */_(ER_RESERVED19, 0, "Reserved19") \ - /* 20 */_(ER_RESERVED20, 0, "Reserved20") \ - /* 21 */_(ER_RESERVED21, 0, "Reserved21") \ - /* 22 */_(ER_RESERVED22, 0, "Reserved22") \ - /* 23 */_(ER_RESERVED23, 0, "Reserved23") \ - /* end of silverproxy error codes */ \ - /* 24 */_(ER_DROP_SPACE, 2, "Can't drop space %u: %s") \ - /* 25 */_(ER_ALTER_SPACE, 2, "Can't modify space %u: %s") \ - /* 26 */_(ER_FIBER_STACK, 2, "Can not create a new fiber: recursion limit reached") \ - /* 27 */_(ER_MODIFY_INDEX, 2, "Can't create or modify index %u in space %u: %s") \ - /* 28 */_(ER_TUPLE_FORMAT_LIMIT, 2, "Tuple format limit reached: %u") \ - /* 29 */_(ER_LAST_DROP, 2, "Can't drop the primary key in a system space, space id %u") \ - /* 30 */_(ER_DROP_PRIMARY_KEY, 2, "Can't drop primary key in space %u while secondary keys exist") \ - /* 31 */_(ER_SPACE_ARITY, 2, "Tuple field count %u does not match space %u arity %u") \ - /* 32 */_(ER_INDEX_ARITY, 2, "Tuple field count %u is less than required by a defined index (expected %u)") \ - /* 33 */_(ER_UNUSED33, 2, "Unused33") \ - /* 34 */_(ER_UNUSED34, 2, "Unused34") \ - /* 35 */_(ER_NO_SUCH_TRIGGER, 2, "Trigger is not found") \ - /* 36 */_(ER_INVALID_MSGPACK, 2, "Invalid MsgPack") \ - /* 37 */_(ER_TUPLE_NOT_ARRAY, 2, "Tuple/Key must be MsgPack array") \ - /* 38 */_(ER_KEY_FIELD_TYPE, 2, "Supplied key type of part %u does not match index part type: expected %s") \ - /* 39 */_(ER_WAL_IO, 2, "Failed to write to disk") \ - /* 40 */_(ER_FIELD_TYPE, 2, "Tuple field %u type does not match one required by operation: expected %s") \ - /* 41 */_(ER_ARG_TYPE, 2, "Argument type in operation on field %u does not match field type: expected a %s") \ - /* 42 */_(ER_SPLICE, 2, "Field SPLICE error: %s") \ - /* 43 */_(ER_TUPLE_IS_TOO_LONG, 2, "Tuple is too long %u") \ - /* 44 */_(ER_UNKNOWN_UPDATE_OP, 2, "Unknown UPDATE operation") \ - /* 45 */_(ER_EXACT_MATCH, 2, "Invalid key part count in an exact match (expected %u, got %u)") \ - /* 46 */_(ER_FIELD_TYPE_MISMATCH, 2, "Ambiguous field type in index %u, key part %u. Requested type is %s but the field has previously been defined as %s") \ - /* 47 */_(ER_KEY_PART_COUNT, 2, "Invalid key part count (expected [0..%u], got %u)") \ - /* 48 */_(ER_PROC_RET, 2, "msgpack.encode: can not encode Lua type '%s'") \ - /* 49 */_(ER_TUPLE_NOT_FOUND, 2, "Tuple doesn't exist in index %u") \ - /* 50 */_(ER_NO_SUCH_PROC, 2, "Procedure '%.*s' is not defined") \ - /* 51 */_(ER_PROC_LUA, 2, "%s") \ - /* 52 */_(ER_SPACE_DISABLED, 2, "Space %u is disabled") \ - /* 53 */_(ER_NO_SUCH_INDEX, 2, "No index #%u is defined in space %u") \ - /* 54 */_(ER_NO_SUCH_FIELD, 2, "Field %u was not found in the tuple") \ - /* 55 */_(ER_TUPLE_FOUND, 2, "Duplicate key exists in unique index %u") \ - /* 56 */_(ER_UPDATE_FIELD, 2, "Field %u UPDATE error: %s") \ - /* 57 */_(ER_NO_SUCH_SPACE, 2, "Space %u does not exist") + /* 1 */_(ER_ILLEGAL_PARAMS, 2, "Illegal parameters, %s") \ + /* 2 */_(ER_MEMORY_ISSUE, 1, "Failed to allocate %u bytes in %s for %s") \ + /* 3 */_(ER_TUPLE_FOUND, 2, "Duplicate key exists in unique index %u") \ + /* 4 */_(ER_TUPLE_NOT_FOUND, 2, "Tuple doesn't exist in index %u") \ + /* 5 */_(ER_UNSUPPORTED, 2, "%s does not support %s") \ + /* 6 */_(ER_NONMASTER, 2, "Can't modify data on a replication slave. My master is: %s") \ + /* 7 */_(ER_SECONDARY, 2, "Can't modify data upon a request on the secondary port.") \ + /* 8 */_(ER_INJECTION, 2, "Error injection '%s'") \ + /* 9 */_(ER_CREATE_SPACE, 2, "Failed to create space %u: %s") \ + /* 10 */_(ER_SPACE_EXISTS, 2, "Space %u already exists") \ + /* 11 */_(ER_DROP_SPACE, 2, "Can't drop space %u: %s") \ + /* 12 */_(ER_ALTER_SPACE, 2, "Can't modify space %u: %s") \ + /* 13 */_(ER_INDEX_TYPE, 2, "Unsupported index type supplied for index %u in space %u") \ + /* 14 */_(ER_MODIFY_INDEX, 2, "Can't create or modify index %u in space %u: %s") \ + /* 15 */_(ER_LAST_DROP, 2, "Can't drop the primary key in a system space, space id %u") \ + /* 16 */_(ER_TUPLE_FORMAT_LIMIT, 2, "Tuple format limit reached: %u") \ + /* 17 */_(ER_DROP_PRIMARY_KEY, 2, "Can't drop primary key in space %u while secondary keys exist") \ + /* 18 */_(ER_KEY_FIELD_TYPE, 2, "Supplied key type of part %u does not match index part type: expected %s") \ + /* 19 */_(ER_EXACT_MATCH, 2, "Invalid key part count in an exact match (expected %u, got %u)") \ + /* 20 */_(ER_INVALID_MSGPACK, 2, "Invalid MsgPack") \ + /* 21 */_(ER_PROC_RET, 2, "msgpack.encode: can not encode Lua type '%s'") \ + /* 22 */_(ER_TUPLE_NOT_ARRAY, 2, "Tuple/Key must be MsgPack array") \ + /* 23 */_(ER_FIELD_TYPE, 2, "Tuple field %u type does not match one required by operation: expected %s") \ + /* 24 */_(ER_FIELD_TYPE_MISMATCH, 2, "Ambiguous field type in index %u, key part %u. Requested type is %s but the field has previously been defined as %s") \ + /* 25 */_(ER_SPLICE, 2, "Field SPLICE error: %s") \ + /* 26 */_(ER_ARG_TYPE, 2, "Argument type in operation on field %u does not match field type: expected a %s") \ + /* 27 */_(ER_TUPLE_IS_TOO_LONG, 2, "Tuple is too long %u") \ + /* 28 */_(ER_UNKNOWN_UPDATE_OP, 2, "Unknown UPDATE operation") \ + /* 29 */_(ER_UPDATE_FIELD, 2, "Field %u UPDATE error: %s") \ + /* 30 */_(ER_FIBER_STACK, 2, "Can not create a new fiber: recursion limit reached") \ + /* 31 */_(ER_KEY_PART_COUNT, 2, "Invalid key part count (expected [0..%u], got %u)") \ + /* 32 */_(ER_PROC_LUA, 2, "%s") \ + /* 33 */_(ER_NO_SUCH_PROC, 2, "Procedure '%.*s' is not defined") \ + /* 34 */_(ER_NO_SUCH_TRIGGER, 2, "Trigger is not found") \ + /* 35 */_(ER_NO_SUCH_INDEX, 2, "No index #%u is defined in space %u") \ + /* 36 */_(ER_NO_SUCH_SPACE, 2, "Space %u does not exist") \ + /* 37 */_(ER_NO_SUCH_FIELD, 2, "Field %u was not found in the tuple") \ + /* 38 */_(ER_SPACE_ARITY, 2, "Tuple field count %u does not match space %u arity %u") \ + /* 39 */_(ER_INDEX_ARITY, 2, "Tuple field count %u is less than required by a defined index (expected %u)") \ + /* 40 */_(ER_WAL_IO, 2, "Failed to write to disk") \ /* @@ -138,10 +118,9 @@ static inline const char *tnt_errcode_str(uint32_t errcode) static inline uint32_t tnt_errcode_val(uint32_t errcode) { - if (errcode >= tnt_error_codes_enum_MAX) - return (errcode << 8) | 2; /* non-recoverable */ - - return (errcode << 8) | tnt_error_codes[errcode].errflags; + uint32_t errflags = errcode < tnt_error_codes_enum_MAX ? + tnt_error_codes[errcode].errflags : 2; /* non-recoverable */ + return (errcode << 8) | errflags; } @@ -150,7 +129,7 @@ static inline uint32_t tnt_errcode_val(uint32_t errcode) static inline const char *tnt_errcode_desc(uint32_t errcode) { if (errcode >= tnt_error_codes_enum_MAX) - return ""; + return "Unknown error"; return tnt_error_codes[errcode].errdesc; } diff --git a/src/lua/init.cc b/src/lua/init.cc index 759e82f5f7..87d03284d9 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -238,7 +238,7 @@ tarantool_lua_error_init(struct lua_State *L) { const char *name = tnt_error_codes[i].errstr; if (strstr(name, "UNUSED") || strstr(name, "RESERVED")) continue; - lua_pushnumber(L, tnt_errcode_val(i)); + lua_pushnumber(L, i); lua_setfield(L, -2, name); } lua_pop(L, 1); diff --git a/test/box/lua_misc.result b/test/box/lua_misc.result index 1044b6d8c7..711264596e 100644 --- a/test/box/lua_misc.result +++ b/test/box/lua_misc.result @@ -126,49 +126,47 @@ end; ... t; --- -- - 'box.error.ER_NO_SUCH_INDEX : 13570' - - 'box.error.ER_PROC_RET : 12290' - - 'box.error.ER_CREATE_SPACE : 2050' - - 'box.error.ER_TUPLE_FORMAT_LIMIT : 7170' - - 'box.error.ER_FIELD_TYPE : 10242' +- - 'box.error.ER_NO_SUCH_INDEX : 35' + - 'box.error.ER_TUPLE_FOUND : 3' + - 'box.error.ER_CREATE_SPACE : 9' + - 'box.error.ER_TUPLE_FORMAT_LIMIT : 16' + - 'box.error.ER_FIELD_TYPE : 23' - 'box.error.ER_OK : 0' - - 'box.error.ER_TUPLE_NOT_FOUND : 12546' - - 'box.error.ER_INDEX_ARITY : 8194' - - 'box.error.ER_WAL_IO : 9986' - - 'box.error.ER_INJECTION : 2306' - - 'box.error.ER_DROP_PRIMARY_KEY : 7682' - - 'box.error.ER_INDEX_TYPE : 1282' - - 'box.error.ER_ARG_TYPE : 10498' - - 'box.error.ER_INVALID_MSGPACK : 9218' - - 'box.error.ER_KEY_PART_COUNT : 12034' - - 'box.error.ER_MEMORY_ISSUE : 1793' - - 'box.error.ER_ILLEGAL_PARAMS : 514' - - 'box.error.ER_KEY_FIELD_TYPE : 9730' - - 'box.error.ER_NONMASTER : 258' - - 'box.error.ER_FIELD_TYPE_MISMATCH : 11778' - - 'box.error.ER_MODIFY_INDEX : 6914' - - 'box.error.ER_EXACT_MATCH : 11522' - - 'box.error.ER_SECONDARY : 770' - - 'box.error.ER_NO_SUCH_SPACE : 14594' - - 'box.error.ER_TUPLE_FOUND : 14082' - - 'box.error.ER_UPDATE_FIELD : 14338' - - 'box.error.ER_DROP_SPACE : 6146' - - 'box.error.ER_UNKNOWN_UPDATE_OP : 11266' - - 'box.error.ER_NO_SUCH_FIELD : 13826' - - 'box.error.ER_UNSUPPORTED : 2562' - - 'box.error.ER_SPACE_DISABLED : 13314' - - 'box.error.ER_TUPLE_NOT_ARRAY : 9474' - - 'box.error.ER_PROC_LUA : 13058' - - 'box.error.ER_FIBER_STACK : 6658' - - 'box.error.ER_ALTER_SPACE : 6402' - - 'box.error.ER_TUPLE_IS_RO : 1025' - - 'box.error.ER_LAST_DROP : 7426' - - 'box.error.ER_NO_SUCH_PROC : 12802' - - 'box.error.ER_SPACE_EXISTS : 1538' - - 'box.error.ER_NO_SUCH_TRIGGER : 8962' - - 'box.error.ER_SPACE_ARITY : 7938' - - 'box.error.ER_SPLICE : 10754' - - 'box.error.ER_TUPLE_IS_TOO_LONG : 11010' + - 'box.error.ER_TUPLE_NOT_FOUND : 4' + - 'box.error.ER_INDEX_ARITY : 39' + - 'box.error.ER_WAL_IO : 40' + - 'box.error.ER_INJECTION : 8' + - 'box.error.ER_DROP_PRIMARY_KEY : 17' + - 'box.error.ER_INDEX_TYPE : 13' + - 'box.error.ER_ARG_TYPE : 26' + - 'box.error.ER_INVALID_MSGPACK : 20' + - 'box.error.ER_KEY_PART_COUNT : 31' + - 'box.error.ER_MEMORY_ISSUE : 2' + - 'box.error.ER_ILLEGAL_PARAMS : 1' + - 'box.error.ER_KEY_FIELD_TYPE : 18' + - 'box.error.ER_NONMASTER : 6' + - 'box.error.ER_FIELD_TYPE_MISMATCH : 24' + - 'box.error.ER_MODIFY_INDEX : 14' + - 'box.error.ER_EXACT_MATCH : 19' + - 'box.error.ER_SECONDARY : 7' + - 'box.error.ER_UPDATE_FIELD : 29' + - 'box.error.ER_FIBER_STACK : 30' + - 'box.error.ER_UNKNOWN_UPDATE_OP : 28' + - 'box.error.ER_SPACE_ARITY : 38' + - 'box.error.ER_UNSUPPORTED : 5' + - 'box.error.ER_NO_SUCH_FIELD : 37' + - 'box.error.ER_TUPLE_NOT_ARRAY : 22' + - 'box.error.ER_NO_SUCH_SPACE : 36' + - 'box.error.ER_LAST_DROP : 15' + - 'box.error.ER_ALTER_SPACE : 12' + - 'box.error.ER_NO_SUCH_PROC : 33' + - 'box.error.ER_SPACE_EXISTS : 10' + - 'box.error.ER_PROC_LUA : 32' + - 'box.error.ER_PROC_RET : 21' + - 'box.error.ER_NO_SUCH_TRIGGER : 34' + - 'box.error.ER_TUPLE_IS_TOO_LONG : 27' + - 'box.error.ER_SPLICE : 25' + - 'box.error.ER_DROP_SPACE : 11' ... space:drop(); --- diff --git a/test/lib/sql_ast.py b/test/lib/sql_ast.py index d84cafc564..b58d7975d7 100644 --- a/test/lib/sql_ast.py +++ b/test/lib/sql_ast.py @@ -17,64 +17,47 @@ from tarantool.request import ( ) ER = { - 0: "ER_OK" , - 1: "ER_NONMASTER" , - 2: "ER_ILLEGAL_PARAMS" , - 3: "ER_SECONDARY" , - 4: "ER_TUPLE_IS_RO" , - 5: "ER_INDEX_TYPE" , - 6: "ER_SPACE_EXISTS" , - 7: "ER_MEMORY_ISSUE" , - 8: "ER_CREATE_SPACE" , - 9: "ER_INJECTION" , - 10: "ER_UNSUPPORTED" , - 11: "ER_RESERVED11" , - 12: "ER_RESERVED12" , - 13: "ER_RESERVED13" , - 14: "ER_RESERVED14" , - 15: "ER_RESERVED15" , - 16: "ER_RESERVED16" , - 17: "ER_RESERVED17" , - 18: "ER_RESERVED18" , - 19: "ER_RESERVED19" , - 20: "ER_RESERVED20" , - 21: "ER_RESERVED21" , - 22: "ER_RESERVED22" , - 23: "ER_RESERVED23" , - 24: "ER_DROP_SPACE" , - 25: "ER_ALTER_SPACE" , - 26: "ER_FIBER_STACK" , - 27: "ER_MODIFY_INDEX" , - 28: "ER_TUPLE_FORMAT_LIMIT" , - 29: "ER_LAST_DROP" , - 30: "ER_DROP_PRIMARY_KEY" , - 31: "ER_SPACE_ARITY" , - 32: "ER_INDEX_ARITY" , - 33: "ER_UNUSED33" , - 34: "ER_UNUSED34" , - 35: "ER_UNUSED35" , - 36: "ER_UNUSED36" , - 37: "ER_UNUSED37" , - 38: "ER_KEY_FIELD_TYPE" , - 39: "ER_WAL_IO" , - 40: "ER_FIELD_TYPE" , - 41: "ER_ARG_TYPE" , - 42: "ER_SPLICE" , - 43: "ER_TUPLE_IS_TOO_LONG" , - 44: "ER_UNKNOWN_UPDATE_OP" , - 45: "ER_EXACT_MATCH" , - 46: "ER_FIELD_TYPE_MISMATCH" , - 47: "ER_KEY_PART_COUNT" , - 48: "ER_PROC_RET" , - 49: "ER_TUPLE_NOT_FOUND" , - 50: "ER_NO_SUCH_PROC" , - 51: "ER_PROC_LUA" , - 52: "ER_SPACE_DISABLED" , - 53: "ER_NO_SUCH_INDEX" , - 54: "ER_NO_SUCH_FIELD" , - 55: "ER_TUPLE_FOUND" , - 56: "ER_UNUSED" , - 57: "ER_NO_SUCH_SPACE" + 0: "ER_OK" , + 1: "ER_ILLEGAL_PARAMS" , + 2: "ER_MEMORY_ISSUE" , + 3: "ER_TUPLE_FOUND" , + 4: "ER_TUPLE_NOT_FOUND" , + 5: "ER_UNSUPPORTED" , + 6: "ER_NONMASTER" , + 7: "ER_SECONDARY" , + 8: "ER_INJECTION" , + 9: "ER_CREATE_SPACE" , + 10: "ER_SPACE_EXISTS" , + 11: "ER_DROP_SPACE" , + 12: "ER_ALTER_SPACE" , + 13: "ER_INDEX_TYPE" , + 14: "ER_MODIFY_INDEX" , + 15: "ER_LAST_DROP" , + 16: "ER_TUPLE_FORMAT_LIMIT" , + 17: "ER_DROP_PRIMARY_KEY" , + 18: "ER_KEY_FIELD_TYPE" , + 19: "ER_EXACT_MATCH" , + 20: "ER_INVALID_MSGPACK" , + 21: "ER_PROC_RET" , + 22: "ER_TUPLE_NOT_ARRAY" , + 23: "ER_FIELD_TYPE" , + 24: "ER_FIELD_TYPE_MISMATCH", + 25: "ER_SPLICE" , + 26: "ER_ARG_TYPE" , + 27: "ER_TUPLE_IS_TOO_LONG" , + 28: "ER_UNKNOWN_UPDATE_OP" , + 29: "ER_UPDATE_FIELD" , + 30: "ER_FIBER_STACK" , + 31: "ER_KEY_PART_COUNT" , + 32: "ER_PROC_LUA" , + 33: "ER_NO_SUCH_PROC" , + 34: "ER_NO_SUCH_TRIGGER" , + 35: "ER_NO_SUCH_INDEX" , + 36: "ER_NO_SUCH_SPACE" , + 37: "ER_NO_SUCH_FIELD" , + 38: "ER_SPACE_ARITY" , + 39: "ER_INDEX_ARITY" , + 40: "ER_WAL_IO" } errstr = """--- -- GitLab