Tarantool development patches archive
 help / color / mirror / Atom feed
From: Leonid Vasiliev <lvasiliev@tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH V4 5/6] error: update constructors of some errors
Date: Thu, 16 Apr 2020 20:38:44 +0300	[thread overview]
Message-ID: <ff71c989ef381bb9f3d03754ca439054817e052d.1587058424.git.lvasiliev@tarantool.org> (raw)
In-Reply-To: <cover.1587058424.git.lvasiliev@tarantool.org>
In-Reply-To: <cover.1587058424.git.lvasiliev@tarantool.org>

We want to have a transparent marshalling through net.box
for errors. To do this, we need to recreate the error
on the client side with the same parameters as on the server.
For convenience, we update AccessDeniedError constructor
which has points to static strings and add the XlogGapError
constructor that does not require vclock.

Needed for #4398
---
 src/box/error.cc | 18 +++++++++---------
 src/box/error.h  |  8 ++++++--
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/box/error.cc b/src/box/error.cc
index c8fadfb..cb134ba 100644
--- a/src/box/error.cc
+++ b/src/box/error.cc
@@ -253,6 +253,13 @@ XlogGapError::XlogGapError(const char *file, unsigned line,
 		 (long long) vclock_sum(to), s_to ? s_to : "");
 }
 
+XlogGapError::XlogGapError(const char *file, unsigned line,
+			   const char *msg)
+		: XlogError(&type_XlogGapError, file, line)
+{
+	error_format_msg(this, "%s", msg);
+}
+
 struct error *
 BuildXlogGapError(const char *file, unsigned line,
 		  const struct vclock *from, const struct vclock *to)
@@ -289,15 +296,8 @@ AccessDeniedError::AccessDeniedError(const char *file, unsigned int line,
 
 	struct on_access_denied_ctx ctx = {access_type, object_type, object_name};
 	trigger_run(&on_access_denied, (void *) &ctx);
-	/*
-	 * We want to use ctx parameters as error parameters
-	 * later, so we have to alloc space for it.
-	 * As m_access_type and m_object_type are constant
-	 * literals they are statically  allocated. We must copy
-	 * only m_object_name.
-	 */
-	m_object_type = object_type;
-	m_access_type = access_type;
+	m_object_type = strdup(object_type);
+	m_access_type = strdup(access_type);
 	m_object_name = strdup(object_name);
 }
 
diff --git a/src/box/error.h b/src/box/error.h
index 311d543..f70d6cb 100644
--- a/src/box/error.h
+++ b/src/box/error.h
@@ -244,6 +244,8 @@ public:
 	~AccessDeniedError()
 	{
 		free(m_object_name);
+		free(m_object_type);
+		free(m_access_type);
 	}
 
 	const char *
@@ -266,11 +268,11 @@ public:
 
 private:
 	/** Type of object the required access was denied to */
-	const char *m_object_type;
+	char *m_object_type;
 	/** Name of object the required access was denied to */
 	char *m_object_name;
 	/** Type of declined access */
-	const char *m_access_type;
+	char *m_access_type;
 };
 
 /**
@@ -300,6 +302,8 @@ struct XlogGapError: public XlogError
 {
 	XlogGapError(const char *file, unsigned line,
 		     const struct vclock *from, const struct vclock *to);
+	XlogGapError(const char *file, unsigned line,
+		     const char *msg);
 
 	virtual void raise() { throw this; }
 };
-- 
2.7.4

  parent reply	other threads:[~2020-04-16 17:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 17:38 [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 1/6] error: add custom error type Leonid Vasiliev
2020-04-17  0:49   ` Vladislav Shpilevoy
2020-04-18 17:14     ` lvasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 2/6] error: send custom type in IProto Leonid Vasiliev
2020-04-17  0:51   ` Vladislav Shpilevoy
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 3/6] session: add offset to SQL session settings array Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 4/6] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-16 19:48   ` Konstantin Osipov
2020-04-17  0:51     ` Vladislav Shpilevoy
2020-04-17  7:35       ` Konstantin Osipov
2020-04-16 17:38 ` Leonid Vasiliev [this message]
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 6/6] error: add error MsgPack encoding Leonid Vasiliev
2020-04-17  0:58   ` Vladislav Shpilevoy
2020-04-18 17:46     ` lvasiliev
2020-04-17  0:51 ` [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ff71c989ef381bb9f3d03754ca439054817e052d.1587058424.git.lvasiliev@tarantool.org \
    --to=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH V4 5/6] error: update constructors of some errors' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox