Tarantool development patches archive
 help / color / mirror / Atom feed
From: Roman Khabibov <roman.habibov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Subject: [PATCH 2/2 v2] fio: show function name in all fio errors
Date: Tue,  4 Dec 2018 19:00:38 +0300	[thread overview]
Message-ID: <7c3e48bc5b444fa3b5ae9268229c02da45770c64.1543938959.git.roman.habibov@tarantool.org> (raw)
In-Reply-To: <cover.1543938959.git.roman.habibov@tarantool.org>

From: Vladislav Shpilevoy <v.shpilevoy@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

  parent reply	other threads:[~2018-12-04 16:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-04 16:00 [PATCH 0/2 " Roman Khabibov
2018-12-04 16:00 ` [PATCH 1/2 v2] lua: modify the error message in 'fio.pathjoin' Roman Khabibov
2018-12-04 16:00 ` Roman Khabibov [this message]
2018-12-04 16:12 ` [PATCH 0/2 v2] fio: show function name in all fio errors Vladimir Davydov
2018-12-07  7:25   ` Alexander Turenko
2018-12-08 13:41     ` [tarantool-patches] " roman
2018-12-08 14:36       ` Alexander Turenko
2018-12-08 15:02         ` roman
2018-12-08 15:12           ` Alexander Turenko
2018-12-09  9:36       ` Vladimir Davydov

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=7c3e48bc5b444fa3b5ae9268229c02da45770c64.1543938959.git.roman.habibov@tarantool.org \
    --to=roman.habibov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 2/2 v2] fio: show function name in all fio 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