From 72ccbd51fc5458874f614b0387f538fe17b30601 Mon Sep 17 00:00:00 2001
From: Alexandr <a.lyapunov@corp.mail.ru>
Date: Wed, 1 Oct 2014 16:41:38 +0400
Subject: [PATCH] fix gh-521 update-error-message

---
 src/box/lua/schema.lua   | 27 ++++++++++++++++-----------
 test/box/update.result   | 22 ++++++++++++++++++++++
 test/box/update.test.lua |  8 ++++++++
 3 files changed, 46 insertions(+), 11 deletions(-)

diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index 0999acf65e..27afec3505 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -443,19 +443,24 @@ end
 -- Change one-based indexing in update commands to zero-based.
 --
 local function normalize_update_ops(ops)
+    if type(ops) ~= 'table' then
+        return ops;
+    end
     for _, op in ipairs(ops) do
-        if op[1] == ':' then
-            -- fix offset for splice
-            if op[3] > 0 then
-                op[3] = op[3] - 1
-            elseif op[3] == 0 then
-                box.error(box.error.SPLICE, op[2], "offset is out of bound")
+        if type(op) == 'table' then
+            if op[1] == ':' then
+                -- fix offset for splice
+                if op[3] > 0 then
+                    op[3] = op[3] - 1
+                elseif op[3] == 0 then
+                    box.error(box.error.SPLICE, op[2], "offset is out of bound")
+                end
+            end
+            if op[2] > 0 then
+               op[2] = op[2] - 1
+            elseif op[2] == 0 then
+               box.error(box.error.NO_SUCH_FIELD, op[2])
             end
-        end
-        if op[2] > 0 then
-           op[2] = op[2] - 1
-        elseif op[2] == 0 then
-           box.error(box.error.NO_SUCH_FIELD, op[2])
         end
     end
     return ops
diff --git a/test/box/update.result b/test/box/update.result
index 3dfddd5c53..b2b49e3284 100644
--- a/test/box/update.result
+++ b/test/box/update.result
@@ -330,3 +330,25 @@ s:truncate()
 s:drop()
 ---
 ...
+-- #521: Cryptic error message in update operation
+s = box.schema.create_space('tweedledum')
+---
+...
+s:create_index('pk')
+---
+...
+s:insert{1, 2, 3}
+---
+- [1, 2, 3]
+...
+s:update({1})
+---
+- error: Tuple/Key must be MsgPack array
+...
+s:update({1}, {'=', 1, 1})
+---
+- error: Invalid MsgPack - expected an update operation name (string)
+...
+s:drop()
+---
+...
diff --git a/test/box/update.test.lua b/test/box/update.test.lua
index 4723fef896..010721ce17 100644
--- a/test/box/update.test.lua
+++ b/test/box/update.test.lua
@@ -110,3 +110,11 @@ s = box.space.tweedledum
 s:select{}
 s:truncate()
 s:drop()
+
+-- #521: Cryptic error message in update operation
+s = box.schema.create_space('tweedledum')
+s:create_index('pk')
+s:insert{1, 2, 3}
+s:update({1})
+s:update({1}, {'=', 1, 1})
+s:drop()
-- 
GitLab