From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (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 05DE845C305 for ; Fri, 11 Dec 2020 17:50:13 +0300 (MSK) From: Leonid Vasiliev Date: Fri, 11 Dec 2020 17:49:11 +0300 Message-Id: <2bcd06c2ee8f5fcfdb8e2d0d640ab822362832f7.1607696813.git.lvasiliev@tarantool.org> In-Reply-To: References: In-Reply-To: References: Subject: [Tarantool-patches] [PATCH v2 2/3] sql: set an error to diag in sql_execute() on failure List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, imeevma@tarantool.org, korablev@tarantool.org, sergos@tarantool.org, m.semkin@corp.mail.ru Cc: tarantool-patches@dev.tarantool.org In SQL, on failure sometimes an error sets to the diag, sometimes not. And this can dived to situation as in #5537(SEGFAULT). So, let's set an error to the diag if the result of `sql_execute()` is a failure and there is no error in the diag. Part of #5537 --- After some discussion with Sergos, I added a common diag_set when sql_execute() fails. I wanted to add such a common error by `diag_add()` if diag is not empty, but such a change would entail additional correction in tests. But this patch should be included in the next release, and I want it to be as small as possible. This patchset is about fixes a crash, not about refactoring and improvements. For this I will create separate tasks. src/box/execute.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/box/execute.c b/src/box/execute.c index e14da20..87ebb44 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -687,8 +687,18 @@ sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region) rc = sql_step(stmt); assert(rc != SQL_ROW && rc != 0); } - if (rc != SQL_DONE) + if (rc != SQL_DONE) { + /* + * In SQL, on failure sometimes an error sets to the diag, + * sometimes not. So, let's set an error to the diag if + * the status is a failure and there is no error in the diag. + */ + if (diag_is_empty(diag_get())) { + diag_set(ClientError, ER_SQL_EXECUTE, + "something went wrong"); + } return -1; + } return 0; } -- 2.7.4