]> git.e2factory.org Git - e2factory.git/commitdiff
Change pcall to e2lib.trycall, a wrapper with more debug information
authorTobias Ulmer <tu@emlix.com>
Fri, 7 Feb 2014 17:59:33 +0000 (18:59 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
15 files changed:
generic/e2lib.lua
global/e2-create-project.lua
global/e2-fetch-project.lua
global/e2-install-e2.lua
global/e2.lua
local/e2-build-numbers.lua
local/e2-build.lua
local/e2-cf.lua
local/e2-dlist.lua
local/e2-dsort.lua
local/e2-fetch-sources.lua
local/e2-help.lua
local/e2-ls-project.lua
local/e2-new-source.lua
local/e2-playground.lua

index 9beee2c9950331210c1b3f2299233b8ae81cd622..9ea320f1377ea3e109abaa503962235f9c63c292 100644 (file)
@@ -109,6 +109,24 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.]],
     debuglogfilebuffer = {},
 })
 
+--- Call function in a protected environment. This is a fancy version of the
+-- native pcall() and a poor mans exception mechanism. A traceback of the stack
+-- at the time of the error is sent to logf at level 4 to help with debugging.
+-- @param f Function to call.
+-- @param ... Arguments to the function.
+-- @return True when function ended without an anomaly, false otherwise.
+-- @return If previous result is false, the object or string that was passed
+--         from error(), assert() etc. If the previous result is true, the
+--         first result of the called function.
+-- @return Further results from the called function if any.
+function e2lib.trycall(f, ...)
+    local args = {...}
+    return xpcall(
+        function() return f(unpack(args)) end,
+        function(e) e2lib.logf(4, "%s", debug.traceback("", 2)) return e end
+        )
+end
+
 --- Get current working directory.
 -- @return Current working directory (string) or false on error.
 -- @return Error object on failure.
index c195e8edae156e52f1138fd7a358f2dfacf4bd7d..a0e9f861a62a3dc425ce63aee06b3705ee141bf8 100644 (file)
@@ -306,7 +306,7 @@ local function e2_create_project(arg)
     e2lib.rmtempdir(tmpdir)
 end
 
-local pc, re = pcall(e2_create_project, arg)
+local pc, re = e2lib.trycall(e2_create_project, arg)
 if not pc then
     e2lib.abort(re)
 end
index 17d4aa1dfa8989c3951aaa5ad9f816a98a388ca9..92a3899f74e3ed0def40d741e2721dc6859950ff 100644 (file)
@@ -232,7 +232,7 @@ local function e2_fetch_project(arg)
     end
 end
 
-local pc, re = pcall(e2_fetch_project, arg)
+local pc, re = e2lib.trycall(e2_fetch_project, arg)
 if not pc then
     e2lib.abort(re)
 end
index 10268dac550843c59d057b8bf1a03632b6de755a..418d509874332df59f387f35df19783d56ba893c 100644 (file)
@@ -199,7 +199,7 @@ local function e2_install_e2(arg)
     end
 end
 
-local pc, re = pcall(e2_install_e2, arg)
+local pc, re = e2lib.trycall(e2_install_e2, arg)
 if not pc then
     e2lib.abort(re)
 end
index 42393528ae457a3c2b3a559c85ae8b52c061d13e..fa0e6882b4b19f25f9612aaa689fc54a7edddc61 100644 (file)
@@ -113,7 +113,7 @@ local function e2(arg)
     return nil, rc
 end
 
-local pc, re, rc = pcall(e2, arg)
+local pc, re, rc = e2lib.trycall(e2, arg)
 if not pc then
     e2lib.abort(re)
 end
index 04f74b155fbd001c741be6d0c634c5c6b8b08f64..6c90512a472f983d37cec8b1b5f1a78349213188 100644 (file)
@@ -45,7 +45,7 @@ local function e2_build_numbers(arg)
     error(err.new("e2-build-numbers is deprecated and has been removed"))
 end
 
-local pc, re = pcall(e2_build_numbers, arg)
+local pc, re = e2lib.trycall(e2_build_numbers, arg)
 if not pc then
     e2lib.abort(re)
 end
index 58e5a3416a744c5652765375dd93883245ae94d9..dd86b77f8449a22e946dd942865ab5a0ababd51f 100644 (file)
@@ -230,7 +230,7 @@ local function e2_build(arg)
     end
 end
 
-local pc, re = pcall(e2_build, arg)
+local pc, re = e2lib.trycall(e2_build, arg)
 if not pc then
     e2lib.abort(re)
 end
index 45aec2b43b5f811128052509bf8f83f4c86cc390..3682647558ff15b10fcf42cfb9b018e8e92d0c95 100644 (file)
@@ -385,7 +385,7 @@ local function e2_cf(arg)
     end
 end
 
-local pc, re = pcall(e2_cf, arg)
+local pc, re = e2lib.trycall(e2_cf, arg)
 if not pc then
     e2lib.abort(re)
 end
index f97e2c0ad67154b709343735f0d1e75d8854eeac..8a165c08e09cb228467386f1e0684326e15fa301 100644 (file)
@@ -81,7 +81,7 @@ local function e2_dlist(arg)
     end
 end
 
-local pc, re = pcall(e2_dlist, arg)
+local pc, re = e2lib.trycall(e2_dlist, arg)
 if not pc then
     e2lib.abort(re)
 end
index 0d739453f0363f0a86fde5c6d6099cfbf3d6cc9f..5cb44bc893ff10bddde32b85a4abf5b189c70999 100644 (file)
@@ -62,7 +62,7 @@ local function e2_dsort(arg)
     end
 end
 
-local pc, re = pcall(e2_dsort, arg)
+local pc, re = e2lib.trycall(e2_dsort, arg)
 if not pc then
     e2lib.abort(re)
 end
index ac9294b7cd6755cb99703b0ecc93ce640fe4cc57..d64f43997c824fbd501cee977c06f521993e07f1 100644 (file)
@@ -244,7 +244,7 @@ local function e2_fetch_source(arg)
     end
 end
 
-local pc, re = pcall(e2_fetch_source, arg)
+local pc, re = e2lib.trycall(e2_fetch_source, arg)
 if not pc then
     e2lib.abort(re)
 end
index 432401a741e02a0a6d03a2e172aea50a525b0181..64cb7bc8c7293e9d78ae7a886d4e085e5b8230be 100644 (file)
@@ -285,7 +285,7 @@ local function e2_help(arg)
     end
 end
 
-local pc, re = pcall(e2_help, arg)
+local pc, re = e2lib.trycall(e2_help, arg)
 if not pc then
     e2lib.abort(re)
 end
index 50277a33a117675684c0f4d0922043bcd023d39a..86173196f799e256fc50b204fd6e523dde85ca26 100644 (file)
@@ -326,7 +326,7 @@ local function e2_ls_project(arg)
     return true
 end
 
-local pc, re = pcall(e2_ls_project, arg)
+local pc, re = e2lib.trycall(e2_ls_project, arg)
 if not pc then
     e2lib.abort(re)
 end
index 41b10b9c095ac66adebf7b2bb710762673222ed3..065e6eaff533231fe3411c74c77e41bd31df3df8 100644 (file)
@@ -293,7 +293,7 @@ local function e2_new_source(arg)
     end
 end
 
-local pc, re = pcall(e2_new_source, arg)
+local pc, re = e2lib.trycall(e2_new_source, arg)
 if not pc then
     e2lib.abort(re)
 end
index 69f272f517780caae4d8ac9cf7242a3609bf3b26..e1b3a5eee5c632fe98cb8e8cc2c867f4a9432032 100644 (file)
@@ -132,7 +132,7 @@ local function e2_playground(arg)
     end
 end
 
-local pc, re = pcall(e2_playground, arg)
+local pc, re = e2lib.trycall(e2_playground, arg)
 if not pc then
     e2lib.abort(re)
 end