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 C409C6F3E5; Sat, 6 Nov 2021 02:58:14 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org C409C6F3E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1636156694; 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=Ba1NdZ0p279UMy6JeqqLSdyAwQnpFivpHEZVdBjd0uapQQM3g5Q1/fSsyYnMtuXwY BBvEAZ/5M6CyW8AG/Pq/1KHxYGvMaOJVG6f9G5+nKAd3IP0BzSCbJ1G7Opi36Qggwo jklKgfFNuBDpSrmzXwiLXlRp1A3HSviodXYxSz1U= Received: from smtpng3.i.mail.ru (smtpng3.i.mail.ru [94.100.177.149]) (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 BE28E6F850 for ; Sat, 6 Nov 2021 02:56:45 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BE28E6F850 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1mj94e-0006s6-KJ; Sat, 06 Nov 2021 02:56:45 +0300 To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org, vdavydov@tarantool.org Date: Sat, 6 Nov 2021 00:56:34 +0100 Message-Id: <375c2c4037f0517fa0801a752266530151544329.1636156453.git.v.shpilevoy@tarantool.org> 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: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9F9D976862A30D4FE73DAF5629B89E81F7BE3C6ABECA89A3F182A05F5380850406596807DC4A014568C2C26216E7242120074452F22068E10D0650EDAF170F672 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70CB15FA6C489297DEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637525B22DCF689D4638638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D88A6BE9A5C36F5D5299A38D4F341CEBB1117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F44604297287769387670735209ECD01F8117BC8BEA471835C12D1D977C4224003CC8364762BB6847A3DEAEFB0F43C7A68FF6260569E8FC8737B5C2249EC8D19AE6D49635B68655334FD4449CB9ECD01F8117BC8BEAAAE862A0553A39223F8577A6DFFEA7CD1D040B6C1ECEA3F43847C11F186F3C59DAA53EE0834AAEE X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505F04FA6A337665710D7CE123554F22BE0 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FC47BC8DA519486CCC4E36BDD02A58517465D78FC2743B0C16B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDBC899C4B0487787E7DC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D340DAE5B306C240CF5EC0CD64FE8B4CAC2AF29E2397BE2937ECD65269C518D0FDEDEFA25330B58424D1D7E09C32AA3244C97956CD02A860BB959CACEF84E6EFF62B4DF56057A86259FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj75A/c671lqWeLmxHnxrCcQ== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DC934D611C3600BF193D273706D0368E23841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 3/9] 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)