From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 5923270653; Fri, 12 Nov 2021 02:57:40 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 5923270653 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636675060; bh=N1GuuDgeJHOoJqoHur4i4PUteiH6qGL1zz4rLT7BmRA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dNwAGjHVtxaL0vxXYXx+onlfgCGhsRMQbp8Cm/6QqNZ/pj7YA9Qjvl47/J5a4p7g0 FY/+a5GZNt3J+qm5XSSjI5NZu3fT6zl55puL3Lj8QEzL83MrNWDVik7N+ofslHybRn /qvcwAFC2Iiish3txnMrK45JXiO0j48kNCoyD3H4= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id A4CA870654 for ; Fri, 12 Nov 2021 02:54:38 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A4CA870654 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mlJtt-0003tY-TZ; Fri, 12 Nov 2021 02:54:38 +0300 To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org Date: Fri, 12 Nov 2021 00:54:25 +0100 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: EEAE043A70213CC8 X-77F55803: 4F1203BC0FB41BD927BBD05C2915ABC3EA6F6B4670DDA5A1324597B560173557182A05F5380850404C228DA9ACA6FE27143AA13CDF9A037B521A5F50F3B7BD4DC122211A8B479A9E29873F82DB0BFB32 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE76D34FAA3D8B31588C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE74FF5DF51D335CFFFEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F27A1F2D19CC249EB170304161C70F5250CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8EDCF5861DED71B2F389733CBF5DBD5E9B5C8C57E37DE458B9E9CE733340B9D5F3BBE47FD9DD3FB595F5C1EE8F4F765FC72CEEB2601E22B093A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4930A3850AC1BE2E735444A83B712AC0148C4224003CC83647689D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B50537BF44C8E1EC058AA375172376824AC8 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FC3C0B852DA0DA35D138E841F86F06A32903242A499378FC71B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBE96A3A8AAADC8934DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D347341ACA13FB8BDD93E441EC38B7671288D297C8B71BE3677067964F846E219A96560617A547A16BF1D7E09C32AA3244C343109F456B28DD8A45C1A834885712763871F383B54D9B3729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4t8MBgWr8bKgMKmY7AcXqw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DE3B47FAC6C2F8D701B5430BC3C7241023841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH v2 04/11] error: move code to struct error from ClientError X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" All optional fields soon will be moved into error_payload. Code was optional too. But it is needed too often, the most used field. The patch moves it into struct error to make it more accessible. Also in future it should allow to drop the hack ClientError::get_errcode() which tries to return error code depending on error type. But could just store the code right away. As a consequence of the patch, errors which didn't have an error code at all before, such as LuajitError, now have it 0 in Lua. Part of #5568 --- src/box/error.cc | 15 +++++++-------- src/box/error.h | 4 +--- src/box/index.cc | 4 ++-- src/box/mp_error.cc | 7 +++---- src/lib/core/diag.c | 1 + src/lib/core/diag.h | 2 ++ src/lua/error.lua | 3 ++- test/engine/func_index.result | 3 ++- test/unit/mp_error.cc | 2 +- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/box/error.cc b/src/box/error.cc index 225b377b7..bc0d46601 100644 --- a/src/box/error.cc +++ b/src/box/error.cc @@ -76,7 +76,7 @@ box_error_set(const char *file, unsigned line, uint32_t code, struct error *e = BuildClientError(file, line, ER_UNKNOWN); ClientError *client_error = type_cast(ClientError, e); if (client_error) { - client_error->m_errcode = code; + client_error->code = code; va_list ap; va_start(ap, fmt); error_vformat_msg(e, fmt, ap); @@ -94,7 +94,7 @@ box_error_new_va(const char *file, unsigned line, uint32_t code, struct error *e = BuildClientError(file, line, ER_UNKNOWN); ClientError *client_error = type_cast(ClientError, e); if (client_error != NULL) { - client_error->m_errcode = code; + client_error->code = code; error_vformat_msg(e, fmt, ap); } return e; @@ -170,7 +170,7 @@ ClientError::ClientError(const type_info *type, const char *file, unsigned line, uint32_t errcode) :Exception(type, file, line) { - m_errcode = errcode; + code = errcode; if (rmean_error) rmean_collect(rmean_error, RMEAN_ERROR, 1); } @@ -181,7 +181,7 @@ ClientError::ClientError(const char *file, unsigned line, { va_list ap; va_start(ap, errcode); - error_vformat_msg(this, tnt_errcode_desc(m_errcode), ap); + error_vformat_msg(this, tnt_errcode_desc(errcode), ap); va_end(ap); } @@ -194,7 +194,7 @@ BuildClientError(const char *file, unsigned line, uint32_t errcode, ...) va_start(ap, errcode); error_vformat_msg(e, tnt_errcode_desc(errcode), ap); va_end(ap); - e->m_errcode = errcode; + e->code = errcode; return e; } catch (OutOfMemory *e) { return e; @@ -204,8 +204,7 @@ BuildClientError(const char *file, unsigned line, uint32_t errcode, ...) void ClientError::log() const { - say_file_line(S_ERROR, file, line, errmsg, "%s", - tnt_errcode_str(m_errcode)); + say_file_line(S_ERROR, file, line, errmsg, "%s", tnt_errcode_str(code)); } @@ -296,7 +295,7 @@ AccessDeniedError::AccessDeniedError(const char *file, unsigned int line, bool run_trigers) :ClientError(&type_AccessDeniedError, file, line, ER_ACCESS_DENIED) { - error_format_msg(this, tnt_errcode_desc(m_errcode), + error_format_msg(this, tnt_errcode_desc(code), access_type, object_type, object_name, user_name); struct on_access_denied_ctx ctx = {access_type, object_type, object_name}; diff --git a/src/box/error.h b/src/box/error.h index 338121dd9..30ab36a97 100644 --- a/src/box/error.h +++ b/src/box/error.h @@ -208,14 +208,12 @@ public: int errcode() const { - return m_errcode; + return code; } ClientError(const char *file, unsigned line, uint32_t errcode, ...); static uint32_t get_errcode(const struct error *e); - /* client errno code */ - int m_errcode; protected: ClientError(const type_info *type, const char *file, unsigned line, uint32_t errcode); diff --git a/src/box/index.cc b/src/box/index.cc index 0651868d3..be14827be 100644 --- a/src/box/index.cc +++ b/src/box/index.cc @@ -47,8 +47,8 @@ UnsupportedIndexFeature::UnsupportedIndexFeature(const char *file, : ClientError(file, line, ER_UNKNOWN) { struct space *space = space_cache_find_xc(index_def->space_id); - m_errcode = ER_UNSUPPORTED_INDEX_FEATURE; - error_format_msg(this, tnt_errcode_desc(m_errcode), index_def->name, + code = ER_UNSUPPORTED_INDEX_FEATURE; + error_format_msg(this, tnt_errcode_desc(code), index_def->name, index_type_strs[index_def->type], space->def->name, space->def->engine_name, what); } diff --git a/src/box/mp_error.cc b/src/box/mp_error.cc index 059f9bc85..35c770400 100644 --- a/src/box/mp_error.cc +++ b/src/box/mp_error.cc @@ -261,10 +261,8 @@ missing_fields: } if (strcmp(mp_error->type, "ClientError") == 0) { - ClientError *e = new ClientError(mp_error->file, mp_error->line, - ER_UNKNOWN); - e->m_errcode = mp_error->code; - err = e; + err = new ClientError(mp_error->file, mp_error->line, + ER_UNKNOWN); } else if (strcmp(mp_error->type, "CustomError") == 0) { if (mp_error->custom_type == NULL) goto missing_fields; @@ -320,6 +318,7 @@ missing_fields: err = new ClientError(mp_error->file, mp_error->line, ER_UNKNOWN); } + err->code = mp_error->code; err->saved_errno = mp_error->saved_errno; error_format_msg(err, "%s", mp_error->message); return err; diff --git a/src/lib/core/diag.c b/src/lib/core/diag.c index f872be6a7..b557ca667 100644 --- a/src/lib/core/diag.c +++ b/src/lib/core/diag.c @@ -116,6 +116,7 @@ error_create(struct error *e, e->type = type; e->refs = 0; e->saved_errno = 0; + e->code = 0; if (file != NULL) { snprintf(e->file, sizeof(e->file), "%s", file); e->line = line; diff --git a/src/lib/core/diag.h b/src/lib/core/diag.h index d7d09f6fb..30b8d2f5d 100644 --- a/src/lib/core/diag.h +++ b/src/lib/core/diag.h @@ -87,6 +87,8 @@ struct error { * to the standard library, then it is 0. */ int saved_errno; + /** Error code. Shortest possible description of error's reason. */ + int code; /** Line number. */ unsigned line; /* Source file name. */ diff --git a/src/lua/error.lua b/src/lua/error.lua index ebc784f07..9fb227df4 100644 --- a/src/lua/error.lua +++ b/src/lua/error.lua @@ -18,6 +18,7 @@ struct error { const struct type_info *_type; int64_t _refs; int _saved_errno; + int code; /** Line number. */ unsigned _line; /* Source file name. */ @@ -158,7 +159,7 @@ local function error_unpack(err) if not ffi.istype('struct error', err) then error("Usage: error:unpack()") end - local result = {} + local result = {code = err.code} for key, getter in pairs(error_fields) do result[key] = getter(err) end diff --git a/test/engine/func_index.result b/test/engine/func_index.result index b689c68ec..d3f44f7be 100644 --- a/test/engine/func_index.result +++ b/test/engine/func_index.result @@ -292,7 +292,8 @@ e = e.prev | ... e:unpack() | --- - | - base_type: LuajitError + | - code: 0 + | base_type: LuajitError | type: LuajitError | message: '[string "return function(tuple) local ..."]:1: attempt | to call global ''require'' (a nil value)' diff --git a/test/unit/mp_error.cc b/test/unit/mp_error.cc index e85d282e7..fe0cd49b9 100644 --- a/test/unit/mp_error.cc +++ b/test/unit/mp_error.cc @@ -349,7 +349,7 @@ test_decode_unknown_type() const char *pos = buffer; struct error *unpacked = error_unpack(&pos, len); error_ref(unpacked); - err.code = 0; + err.code = 1; err.type = "ClientError"; ok(error_is_eq_mp_error(unpacked, &err), "check SomeNewError"); error_unref(unpacked); -- 2.24.3 (Apple Git-128)