From: Tobias Ulmer Date: Fri, 7 Feb 2014 17:59:33 +0000 (+0100) Subject: Change pcall to e2lib.trycall, a wrapper with more debug information X-Git-Tag: e2factory-2.3.15rc1~225 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=a1be4c6e46e59b8c82cf23347b7a8e304d5c5327;p=e2factory.git Change pcall to e2lib.trycall, a wrapper with more debug information Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 9beee2c..9ea320f 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -109,6 +109,24 @@ along with this program. If not, see .]], 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. diff --git a/global/e2-create-project.lua b/global/e2-create-project.lua index c195e8e..a0e9f86 100644 --- a/global/e2-create-project.lua +++ b/global/e2-create-project.lua @@ -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 diff --git a/global/e2-fetch-project.lua b/global/e2-fetch-project.lua index 17d4aa1..92a3899 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -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 diff --git a/global/e2-install-e2.lua b/global/e2-install-e2.lua index 10268da..418d509 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -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 diff --git a/global/e2.lua b/global/e2.lua index 4239352..fa0e688 100644 --- a/global/e2.lua +++ b/global/e2.lua @@ -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 diff --git a/local/e2-build-numbers.lua b/local/e2-build-numbers.lua index 04f74b1..6c90512 100644 --- a/local/e2-build-numbers.lua +++ b/local/e2-build-numbers.lua @@ -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 diff --git a/local/e2-build.lua b/local/e2-build.lua index 58e5a34..dd86b77 100644 --- a/local/e2-build.lua +++ b/local/e2-build.lua @@ -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 diff --git a/local/e2-cf.lua b/local/e2-cf.lua index 45aec2b..3682647 100644 --- a/local/e2-cf.lua +++ b/local/e2-cf.lua @@ -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 diff --git a/local/e2-dlist.lua b/local/e2-dlist.lua index f97e2c0..8a165c0 100644 --- a/local/e2-dlist.lua +++ b/local/e2-dlist.lua @@ -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 diff --git a/local/e2-dsort.lua b/local/e2-dsort.lua index 0d73945..5cb44bc 100644 --- a/local/e2-dsort.lua +++ b/local/e2-dsort.lua @@ -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 diff --git a/local/e2-fetch-sources.lua b/local/e2-fetch-sources.lua index ac9294b..d64f439 100644 --- a/local/e2-fetch-sources.lua +++ b/local/e2-fetch-sources.lua @@ -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 diff --git a/local/e2-help.lua b/local/e2-help.lua index 432401a..64cb7bc 100644 --- a/local/e2-help.lua +++ b/local/e2-help.lua @@ -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 diff --git a/local/e2-ls-project.lua b/local/e2-ls-project.lua index 50277a3..8617319 100644 --- a/local/e2-ls-project.lua +++ b/local/e2-ls-project.lua @@ -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 diff --git a/local/e2-new-source.lua b/local/e2-new-source.lua index 41b10b9..065e6ea 100644 --- a/local/e2-new-source.lua +++ b/local/e2-new-source.lua @@ -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 diff --git a/local/e2-playground.lua b/local/e2-playground.lua index 69f272f..e1b3a5e 100644 --- a/local/e2-playground.lua +++ b/local/e2-playground.lua @@ -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