Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot
@ 2020-05-21 10:33 Dmitriy Koltsov
  2020-05-21 12:10 ` Alexander Turenko
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitriy Koltsov @ 2020-05-21 10:33 UTC (permalink / raw)
  To: tarantool-patches

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot
  2020-05-21 10:33 [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot Dmitriy Koltsov
@ 2020-05-21 12:10 ` Alexander Turenko
  2020-05-21 12:38   ` Dmitriy Koltsov
  2020-05-22  7:41   ` Dmitriy Koltsov
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander Turenko @ 2020-05-21 12:10 UTC (permalink / raw)
  To: Dmitriy Koltsov; +Cc: tarantool-patches

On Thu, May 21, 2020 at 01:33:45PM +0300, Dmitriy Koltsov wrote:
> Make error on box.sequence.<sequence_ex>.<method> call
> similar to space error.
> Ex: 'Use sequence:next(...) instead of sequence.next(...)'.
> 
> Closes #4459

Wrong issue number. Should be #4754.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot
  2020-05-21 12:10 ` Alexander Turenko
@ 2020-05-21 12:38   ` Dmitriy Koltsov
  2020-05-22  7:41   ` Dmitriy Koltsov
  1 sibling, 0 replies; 4+ messages in thread
From: Dmitriy Koltsov @ 2020-05-21 12:38 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 3621 bytes --]


Make error on box.sequence.<sequence_ex>.<method> call
similar to space error.
Ex: 'Use sequence:next(...) instead of sequence.next(...)'.
Closes #4754
---
 
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
 

[-- Attachment #2: Type: text/html, Size: 4529 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot
  2020-05-21 12:10 ` Alexander Turenko
  2020-05-21 12:38   ` Dmitriy Koltsov
@ 2020-05-22  7:41   ` Dmitriy Koltsov
  1 sibling, 0 replies; 4+ messages in thread
From: Dmitriy Koltsov @ 2020-05-22  7:41 UTC (permalink / raw)
  To: Alexander Turenko; +Cc: tarantool-patches

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]


Thank you for your comment. I corrected corresponding branch and patch (sent in the previous message).
  
>Четверг, 21 мая 2020, 15:10 +03:00 от Alexander Turenko <alexander.turenko@tarantool.org>:
> 
>On Thu, May 21, 2020 at 01:33:45PM +0300, Dmitriy Koltsov wrote:
>> Make error on box.sequence.<sequence_ex>.<method> call
>> similar to space error.
>> Ex: 'Use sequence:next(...) instead of sequence.next(...)'.
>>
>> Closes #4459
>Wrong issue number. Should be #4754. 
 
 
--
Dmitriy Koltsov
 

[-- Attachment #2: Type: text/html, Size: 1020 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-22  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-21 10:33 [Tarantool-patches] [PATCH] lua: throw correct error on calls to sequence methods with dot Dmitriy Koltsov
2020-05-21 12:10 ` Alexander Turenko
2020-05-21 12:38   ` Dmitriy Koltsov
2020-05-22  7:41   ` Dmitriy Koltsov

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