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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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