[PATCH 2/2 v2] fio: show function name in all fio errors

Roman Khabibov roman.habibov at tarantool.org
Tue Dec 4 19:00:38 MSK 2018


From: Vladislav Shpilevoy <v.shpilevoy at tarantool.org>

Otherwise it is hard to debug code, throwing
exceptions. fio.pathjoin was just one example among
many.

Follow up #3580
---
 src/lua/fio.lua | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/lua/fio.lua b/src/lua/fio.lua
index 1d0bb4bd1..f279c9f10 100644
--- a/src/lua/fio.lua
+++ b/src/lua/fio.lua
@@ -126,7 +126,7 @@ fio_methods.seek = function(self, offset, whence)
     end
     if type(whence) == 'string' then
         if fio.c.seek[whence] == nil then
-            error(sprintf("Unknown whence: %s", whence))
+            error(sprintf("fio.seek(): unknown whence: %s", whence), 2)
         end
         whence = fio.c.seek[whence]
     else
@@ -164,7 +164,7 @@ fio.open = function(path, flags, mode)
     local iflag = 0
     local imode = 0
     if type(path) ~= 'string' then
-        error("Usage open(path[, flags[, mode]])")
+        error("Usage open(path[, flags[, mode]])", 2)
     end
     if type(flags) ~= 'table' then
         flags = { flags }
@@ -179,7 +179,7 @@ fio.open = function(path, flags, mode)
             iflag = bit.bor(iflag, flag)
         else
             if fio.c.flag[ flag ] == nil then
-                error(sprintf("Unknown flag: %s", flag))
+                error(sprintf("fio.open(): unknown flag: %s", flag), 2)
             end
             iflag = bit.bor(iflag, fio.c.flag[ flag ])
         end
@@ -188,7 +188,7 @@ fio.open = function(path, flags, mode)
     for _, m in pairs(mode) do
         if type(m) == 'string' then
             if fio.c.mode[m] == nil then
-                error(sprintf("Unknown mode: %s", m))
+                error(sprintf("fio.open(): unknown mode: %s", m), 2)
             end
             imode = bit.bor(imode, fio.c.mode[m])
         else
@@ -254,7 +254,7 @@ end
 
 fio.basename = function(path, suffix)
     if type(path) ~= 'string' then
-        error("Usage fio.basename(path[, suffix])")
+        error("Usage fio.basename(path[, suffix])", 2)
     end
 
     path = tostring(path)
@@ -273,7 +273,7 @@ end
 
 fio.dirname = function(path)
     if type(path) ~= 'string' then
-        error("Usage fio.dirname(path)")
+        error("Usage fio.dirname(path)", 2)
     end
     path = ffi.new('char[?]', #path + 1, path)
     return ffi.string(ffi.C.dirname(path))
@@ -297,7 +297,7 @@ fio.abspath = function(path)
     -- following established conventions of fio module:
     -- letting nil through and converting path to string
     if path == nil then
-        error("Usage fio.abspath(path)")
+        error("Usage fio.abspath(path)", 2)
     end
     path = path
     local joined_path = ''
@@ -319,14 +319,14 @@ end
 
 fio.chdir = function(path)
     if type(path)~='string' then
-        error("Usage: fio.chdir(path)")
+        error("Usage: fio.chdir(path)", 2)
     end
     return ffi.C.chdir(path) == 0
 end
 
 fio.listdir = function(path)
     if type(path) ~= 'string' then
-        error("Usage: fio.listdir(path)")
+        error("Usage: fio.listdir(path)", 2)
     end
     local str, err = internal.listdir(path)
     if err ~= nil then
@@ -345,7 +345,7 @@ end
 
 fio.mktree = function(path, mode)
     if type(path) ~= "string" then
-        error("Usage: fio.mktree(path[, mode])")
+        error("Usage: fio.mktree(path[, mode])", 2)
     end
     path = fio.abspath(path)
 
@@ -371,7 +371,7 @@ end
 
 fio.rmtree = function(path)
     if type(path) ~= 'string' then
-        error("Usage: fio.rmtree(path)")
+        error("Usage: fio.rmtree(path)", 2)
     end
     local status, err
     path = fio.abspath(path)
@@ -402,7 +402,7 @@ end
 
 fio.copyfile = function(from, to)
     if type(from) ~= 'string' or type(to) ~= 'string' then
-        error('Usage: fio.copyfile(from, to)')
+        error('Usage: fio.copyfile(from, to)', 2)
     end
     local st = fio.stat(to)
     if st and st:is_dir() then
@@ -417,7 +417,7 @@ end
 
 fio.copytree = function(from, to)
     if type(from) ~= 'string' or type(to) ~= 'string' then
-        error('Usage: fio.copytree(from, to)')
+        error('Usage: fio.copytree(from, to)', 2)
     end
     local status, reason
     local st = fio.stat(from)
-- 
2.19.1




More information about the Tarantool-patches mailing list