From: Dmitriy Koltsov <dkoltsov@picodata.io> To: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot Date: Thu, 21 May 2020 13:33:45 +0300 [thread overview] Message-ID: <20200521103345.6207-1-dkoltsov@picodata.io> (raw) Make error on box.sequence.<sequence_ex>.<method> call similar to space error. Ex: 'Use sequence:next(...) instead of sequence.next(...)'. Closes #4459 --- Github: https://github.com/VifleY/tarantool/tree/dkoltsov-fix-gh4754 Issue: https://github.com/tarantool/tarantool/issues/4754 src/box/lua/schema.lua | 19 +++++++++++++++++++ test/box/sequence.result | 30 ++++++++++++++++++++++++++++++ test/box/sequence.test.lua | 12 ++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index 85fcca562..5fc3128c4 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -1809,14 +1809,25 @@ function box.schema.space.bless(space) end end +-- Helper function to check sequnce:method() usage +local function check_sequence_arg(seq, method) + if type(seq) ~= 'table' or seq.id == nil then + local fmt = 'Use sequence:%s(...) instead of sequence.%s(...)' + error(string.format(fmt, method, method)) + end +end + local sequence_mt = {} sequence_mt.__index = sequence_mt sequence_mt.next = function(self) + check_sequence_arg(self, 'next') return internal.sequence.next(self.id) end sequence_mt.current = function(self) + check_sequence_arg(self, 'current') + local ai64 = buffer.reg1.ai64 local rc = builtin.box_sequence_current(self.id, ai64) if rc < 0 then @@ -1826,18 +1837,26 @@ sequence_mt.current = function(self) end sequence_mt.set = function(self, value) + check_sequence_arg(self, 'set') + return internal.sequence.set(self.id, value) end sequence_mt.reset = function(self) + check_sequence_arg(self, 'reset') + return internal.sequence.reset(self.id) end sequence_mt.alter = function(self, opts) + check_sequence_arg(self, 'alter') + box.schema.sequence.alter(self.id, opts) end sequence_mt.drop = function(self) + check_sequence_arg(self, 'drop') + box.schema.sequence.drop(self.id) end diff --git a/test/box/sequence.result b/test/box/sequence.result index eb1d80d1b..17cdd8021 100644 --- a/test/box/sequence.result +++ b/test/box/sequence.result @@ -2379,3 +2379,33 @@ sq:current() sq:drop() --- ... +-- +-- gh-4754: throw error similar to space.method() error +-- Ex: 'Use sequence:next(...) instead of sequence.next(...)' +-- +sq = box.schema.sequence.create('test') +--- +... +sq.next() +--- +- error: 'builtin/box/schema.lua:1816: Use sequence:next(...) instead of sequence.next(...)' +... +sq.current() +--- +- error: 'builtin/box/schema.lua:1816: Use sequence:current(...) instead of sequence.current(...)' +... +sq.set() +--- +- error: 'builtin/box/schema.lua:1816: Use sequence:set(...) instead of sequence.set(...)' +... +sq.reset() +--- +- error: 'builtin/box/schema.lua:1816: Use sequence:reset(...) instead of sequence.reset(...)' +... +sq.drop() +--- +- error: 'builtin/box/schema.lua:1816: Use sequence:drop(...) instead of sequence.drop(...)' +... +sq:drop() +--- +... \ No newline at end of file diff --git a/test/box/sequence.test.lua b/test/box/sequence.test.lua index a49565b8a..9ea61daef 100644 --- a/test/box/sequence.test.lua +++ b/test/box/sequence.test.lua @@ -812,3 +812,15 @@ sq:current() sq:reset() sq:current() sq:drop() + +-- +-- gh-4754: throw error similar to space.method() error +-- Ex: 'Use sequence:next(...) instead of sequence.next(...)' +-- +sq = box.schema.sequence.create('test') +sq.next() +sq.current() +sq.set() +sq.reset() +sq.drop() +sq:drop() \ No newline at end of file -- 2.17.1
next reply other threads:[~2020-05-21 10:33 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-05-21 10:33 Dmitriy Koltsov [this message] 2020-05-21 12:10 ` Alexander Turenko 2020-05-21 12:38 ` Dmitriy Koltsov 2020-05-22 7:41 ` Dmitriy Koltsov
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=20200521103345.6207-1-dkoltsov@picodata.io \ --to=dkoltsov@picodata.io \ --cc=tarantool-patches@dev.tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot' \ /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