From: Tobias Ulmer Date: Mon, 3 Feb 2014 16:51:16 +0000 (+0100) Subject: Run e2 tools in protected mode, allowing for use of error() X-Git-Tag: e2factory-2.3.15rc1~238 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=b816520ce481c9f8bc7ce59da1b251a82dd35b1c;p=e2factory.git Run e2 tools in protected mode, allowing for use of error() Convert the top level error handling to error(). Not buying us much as of now, but it's a start. Signed-off-by: Tobias Ulmer --- diff --git a/global/e2-create-project.lua b/global/e2-create-project.lua index f6ced72..c195e8e 100644 --- a/global/e2-create-project.lua +++ b/global/e2-create-project.lua @@ -106,29 +106,29 @@ local function e2_create_project(arg) rc, re = e2lib.init() if not rc then - return false, re + error(re) end local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end rc, re = e2lib.init2() if not rc then - return false, re + error(re) end e = err.new("creating project failed") local config, re = e2lib.get_global_config() if not config then - return false, e:cat(re) + error(e:cat(re)) end local scache, re = e2lib.setup_cache() if not scache then - return false, e:cat(re) + error(e:cat(re)) end if #arguments ~= 1 then @@ -138,7 +138,7 @@ local function e2_create_project(arg) local sl, re = e2lib.parse_server_location(arguments[1], e2lib.globals.default_projects_server) if not sl then - return false, e:cat(re) + error(e:cat(re)) end local p = {} @@ -152,7 +152,7 @@ local function e2_create_project(arg) -- create the server side structure local tmpdir, re = e2lib.mktempdir() if not tmpdir then - return false, re + error(re) end local version = string.format("%d\n", p.version) @@ -172,25 +172,25 @@ local function e2_create_project(arg) rc, re = e2lib.mkdir_recursive(e2lib.dirname(sourcefile)) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = eio.file_write(sourcefile, f.content) if not rc then - return false, e:cat(re) + error(e:cat(re)) end flocation = e2lib.join(p.location, f.filename) rc, re = cache.push_file(scache, sourcefile, p.server, flocation, {}) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end e2lib.rmtempdir(tmpdir) tmpdir, re = e2lib.mktempdir() if not tmpdir then - return false, re + error(re) end -- create the initial repository on server side @@ -198,7 +198,7 @@ local function e2_create_project(arg) local rlocation = string.format("%s/proj/%s.git", p.location, p.name) rc, re = generic_git.git_init_db(scache, p.server, rlocation) if not rc then - return false, e:cat(re) + error(e:cat(re)) end -- works up to this point @@ -208,37 +208,37 @@ local function e2_create_project(arg) tmp_repo_url, re = url.parse(string.format("file://%s/.git", tmpdir)) if not tmp_repo_url then - return false, e:cat(re) + error(e:cat(re)) end tmp_repo_path, re = url.to_file_path(tmp_repo_url) if not tmp_repo_path then - return false, e:cat(re) + error(e:cat(re)) end rc, re = generic_git.git_init_db1(tmp_repo_url.url, false) if not rc then - return false, e:cat(re) + error(e:cat(re)) end local gitignore, re = read_template("gitignore") if not gitignore then - return false, re + error(re) end local chroot, re = read_template("proj/chroot") if not chroot then - return false, re + error(re) end local licences, re = read_template("proj/licences") if not licences then - return false, re + error(re) end local env, re = read_template("proj/env") if not env then - return false, re + error(re) end local pconfig, re = read_template("proj/config") if not pconfig then - return false, re + error(re) end pconfig = pconfig:gsub("<>", p.name) pconfig = pconfig:gsub("<>", p.name) @@ -269,30 +269,30 @@ local function e2_create_project(arg) sourcefile = e2lib.join(tmpdir, f.filename) rc, re = e2lib.mkdir_recursive(e2lib.dirname(sourcefile)) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = eio.file_write(sourcefile, f.content) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = generic_git.git_add(tmp_repo_path, { f.filename }) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end local ec = e2lib.join(tmpdir, e2lib.globals.extension_config) rc, re = write_extension_config(ec, config.site.default_extensions) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = generic_git.git_add(tmp_repo_path, { e2lib.globals.extension_config }) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = generic_git.git_commit(tmp_repo_path, { "-m", "project setup" }) if not rc then - return false, e:cat(re) + error(e:cat(re)) end local refspec = "master:refs/heads/master" @@ -300,16 +300,14 @@ local function e2_create_project(arg) rc, re = generic_git.git_push(scache, tmp_repo_path, p.server, rlocation, refspec) if not rc then - return false, e:cat(re) + error(e:cat(re)) end e2lib.rmtempdir(tmpdir) - - return true end -local rc, re = e2_create_project(arg) -if not rc then +local pc, re = pcall(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 7e1752e..17d4aa1 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -39,7 +39,7 @@ local buildconfig = require("buildconfig") local function e2_fetch_project(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local e = err.new("fetching project failed") @@ -51,33 +51,33 @@ local function e2_fetch_project(arg) local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end rc, re = e2lib.init2() if not rc then - return false, re + error(re) end -- setup cache local scache, re = e2lib.setup_cache() if not scache then - return false, e:cat(re) + error(e:cat(re)) end -- standard global tool setup finished if #arguments < 1 then - return false, err.new("specify path to a project to fetch") + error(err.new("specify path to a project to fetch")) end if #arguments > 2 then - return false, err.new("too many arguments") + error(err.new("too many arguments")) end local sl, re = e2lib.parse_server_location(arguments[1], e2lib.globals.default_projects_server) if not sl then - return false, e:cat(re) + error(e:cat(re)) end local p = {} @@ -94,7 +94,7 @@ local function e2_fetch_project(arg) if string.sub(p.destdir, 1, 1) ~= "/" then rc, re = e2lib.cwd() if not rc then - return false, e:cat(re) + error(e:cat(re)) end p.destdir = e2lib.join(rc, p.destdir) @@ -114,27 +114,27 @@ local function e2_fetch_project(arg) -- fetch project descriptor file local tmpdir, re = e2lib.mktempdir() if not tmpdir then - return false, re + error(re) end local location = string.format("%s/version", p.location) local rc, re = cache.fetch_file(scache, p.server, location, tmpdir, nil, { cache = false }) if not rc then - return false, e:cat(re) + error(e:cat(re)) end -- read the version from the first line local version_file = string.format("%s/version", tmpdir) local line, re = eio.file_read_line(version_file) if not line then - return false, e:cat(re) + error(e:cat(re)) end e2lib.rmtempdir() local v = tonumber(line:match("[0-9]+")) if not v or v < 1 or v > 2 then - return false, e:append("unhandled project version") + error(e:append("unhandled project version")) end -- version is 1 or 2 @@ -145,7 +145,7 @@ local function e2_fetch_project(arg) local rc, re = generic_git.git_clone_from_server(scache, p.server, location, p.destdir, skip_checkout) if not rc then - return false, e:cat(re) + error(e:cat(re)) end -- checkout the desired branch, if a branch was given @@ -158,19 +158,19 @@ local function e2_fetch_project(arg) rc, re, id = generic_git.lookup_id(e2lib.join(p.destdir, ".git"), false, "refs/heads/" .. p.branch) if not rc then - return false, e:cat(re) + error(e:cat(re)) end if not id then rc, re = generic_git.git_branch_new1(p.destdir, true, p.branch, "origin/" .. p.branch) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = generic_git.git_checkout1(p.destdir, "refs/heads/" .. p.branch) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end end @@ -188,7 +188,7 @@ local function e2_fetch_project(arg) rc, re = generic_git.git_checkout1(p.destdir, "refs/tags/" .. p.tag) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end @@ -197,14 +197,14 @@ local function e2_fetch_project(arg) local data = string.format("%s\n", p.location) rc, re = eio.file_write(plf, data) if not rc then - return false, e:cat(re) + error(e:cat(re)) end -- write version file local givf = e2lib.join(p.destdir, e2lib.globals.global_interface_version_file) rc, re = eio.file_write(givf, string.format("%d\n", v)) if not rc then - return false, e:cat(re) + error(e:cat(re)) end local e2_install_e2 = @@ -228,14 +228,12 @@ local function e2_fetch_project(arg) rc, re = e2lib.callcmd_log(e2_install_e2, p.destdir) if not rc or rc ~= 0 then local e = err.new("installing local e2 failed") - return false, e:cat(re) + error(e:cat(re)) end - - return true end -local rc, re = e2_fetch_project(arg) -if not rc then +local pc, re = pcall(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 9cd17f1..10268da 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -38,7 +38,7 @@ local buildconfig = require("buildconfig") local function e2_install_e2(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end -- When called from e2-fetch-project, we inherit its arg vector. @@ -48,34 +48,34 @@ local function e2_install_e2(arg) local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end local root = e2lib.locate_project_root() if not root then - return false, err.new("can't locate project root.") + error(err.new("can't locate project root.")) end rc, re = e2lib.init2() if not rc then - return false, re + error(re) end local e = err.new("e2-install-e2 failed") local config, re = e2lib.get_global_config() if not config then - return false, re + error(re) end local servers = config.servers if not servers then - return false, err.new("no servers configured in global config") + error(err.new("no servers configured in global config")) end local scache, re = e2lib.setup_cache() if not scache then - return false, e:cat(re) + error(e:cat(re)) end -- standard global tool setup finished @@ -88,12 +88,12 @@ local function e2_install_e2(arg) local givf = e2lib.join(root, e2lib.globals.global_interface_version_file) local line, re = eio.file_read_line(givf) if not line then - return false, e:cat(re) + error(e:cat(re)) end local v = tonumber(line:match("[0-9]+")) if not v or v < 1 or v > 2 then - return false, e:append("unhandled project version") + error(e:append("unhandled project version")) end -- version is 1 or 2 @@ -104,7 +104,7 @@ local function e2_install_e2(arg) if e2lib.exists(dir) then rc, re = e2lib.unlink_recursive(dir) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end end @@ -113,13 +113,13 @@ local function e2_install_e2(arg) local extensions, re = e2lib.read_extension_config(root) if not extensions then - return false, e:cat(re) + error(e:cat(re)) end local ef = e2lib.join(root, e2lib.globals.e2version_file) local e2version, re = e2lib.parse_e2versionfile(ef) if not e2version then - return false, e:cat(re) + error(e:cat(re)) end local ref @@ -142,13 +142,13 @@ local function e2_install_e2(arg) rc, re = generic_git.git_clone_from_server(scache, server, location, destdir, false) if not rc then - return false, e:cat(re) + error(e:cat(re)) end -- change to requested branch or tag rc, re = generic_git.git_checkout1(destdir, ref) if not rc then - return false, e:cat(re) + error(e:cat(re)) end for _,ex in ipairs(extensions) do @@ -166,19 +166,19 @@ local function e2_install_e2(arg) if e2lib.exists(destdir) then rc, re = e2lib.unlink_recursive(destdir) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end rc, re = generic_git.git_clone_from_server(scache, server, location, destdir, false) if not rc then - return false, e:cat(re) + error(e:cat(re)) end rc, re = generic_git.git_checkout1(destdir, ref) if not rc then - return false, e:cat(re) + error(e:cat(re)) end end @@ -195,14 +195,12 @@ local function e2_install_e2(arg) rc, re = e2lib.callcmd_log(cmd, e2lib.join(root, ".e2/e2")) if not rc or rc ~= 0 then - return false, e:cat(re) + error(e:cat(re)) end - - return true end -local rc, re = e2_install_e2(arg) -if not rc then +local pc, re = pcall(e2_install_e2, arg) +if not pc then e2lib.abort(re) end diff --git a/global/e2.lua b/global/e2.lua index b5b3069..4239352 100644 --- a/global/e2.lua +++ b/global/e2.lua @@ -37,7 +37,7 @@ local err = require("err") local function e2(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end e2option.flag("prefix", "print installation prefix", @@ -58,13 +58,13 @@ local function e2(arg) e2call.toolname = "e2" local opts, re = e2option.parse(arg) if not opts then - return false, re + error(re) end if #opts == 0 then e2option.usage(1) end - return 0 + return nil, 0 else e2call.toolname = e2call.basename e2call.argindex = 1 @@ -90,12 +90,10 @@ local function e2(arg) root, root) env.LUA_CPATH = string.format("%s/.e2/lib/e2/?.so", root) elseif not root then - return false, - err.new("%s is not a global tool and we're not in a ".. - "project environment", e2call.toolname) + error(err.new("%s is not a global tool and we're not in a ".. + "project environment", e2call.toolname)) else - return false, - err.new("%s is neither local nor global tool", e2call.toolname) + error(err.new("%s is neither local nor global tool", e2call.toolname)) end table.insert(cmd, e2call.tool) @@ -109,14 +107,14 @@ local function e2(arg) rc, re = e2lib.callcmd(cmd, {}, nil, env) if not rc then - return false, re + error(re) end - return rc + return nil, rc end -local rc, re = e2(arg) -if not rc then +local pc, re, rc = pcall(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 3b21ad7..04f74b1 100644 --- a/local/e2-build-numbers.lua +++ b/local/e2-build-numbers.lua @@ -34,19 +34,19 @@ local err = require("err") local function e2_build_numbers(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "build-numbers") if not info then - return false, re + error(re) end - return false, err.new("e2-build-numbers is deprecated and has been removed") + error(err.new("e2-build-numbers is deprecated and has been removed")) end -local rc, re = e2_build_numbers(arg) -if not rc then +local pc, re = pcall(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 4c65ae0..58e5a34 100644 --- a/local/e2-build.lua +++ b/local/e2-build.lua @@ -41,12 +41,12 @@ local scm = require("scm") local function e2_build(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "build") if not info then - return false, re + error(re) end e2option.flag("all", "build all results (default unless for working copy)") @@ -78,14 +78,14 @@ local function e2_build(arg) rc, re = cache.set_writeback(info.cache, set.server, false) if not rc then local e = err.new(disable_msg, set.server) - return false, e:cat(re) + error(e:cat(re)) end elseif set.set == "enable" then e2lib.logf(3, enable_msg, set.server) rc, re = cache.set_writeback(info.cache, set.server, true) if not rc then local e = err.new(enable_msg, set.server) - return false, e:cat(re) + error(e:cat(re)) end end end @@ -97,18 +97,18 @@ local function e2_build(arg) local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end -- get build mode from the command line local build_mode, re = policy.handle_commandline_options(opts, true) if not build_mode then - return false, re + error(re) end info, re = e2tool.collect_project_info(info) if not info then - return false, re + error(re) end perform_writeback_settings(writeback) @@ -137,7 +137,7 @@ local function e2_build(arg) local build_mode = nil if opts["branch-mode"] and opts["wc-mode"] then e = err.new("--branch-mode and --wc-mode are mutually exclusive") - return false, e + error(e) end if opts["branch-mode"] then -- selected results get a special build mode @@ -152,16 +152,13 @@ local function e2_build(arg) local playground = opts["playground"] if playground then if opts.release then - return false, - err.new("--release and --playground are mutually exclusive") + error(err.new("--release and --playground are mutually exclusive")) end if opts.all then - return false, - err.new("--all and --playground are mutually exclusive") + error(err.new("--all and --playground are mutually exclusive")) end if #arguments ~= 1 then - return false, - err.new("please select one single result for the playground") + error(err.new("please select one single result for the playground")) end end local force_rebuild = opts["force-rebuild"] @@ -171,7 +168,7 @@ local function e2_build(arg) rc, re = e2tool.select_results(info, results, force_rebuild, keep_chroot, build_mode, playground) if not rc then - return false, re + error(re) end -- a list of results to build, topologically sorted @@ -180,31 +177,31 @@ local function e2_build(arg) local re sel_res, re = e2tool.dlist_recursive(info, results) if not sel_res then - return false, re + error(re) end else local re sel_res, re = e2tool.dsort(info) if not sel_res then - return false, re + error(re) end end rc, re = e2tool.print_selection(info, sel_res) if not rc then - return false, re + error(re) end if opts.release then local version_table, re = e2lib.parse_e2versionfile( e2lib.join(info.root, e2lib.globals.e2version_file)) if not version_table then - return false, re + error(re) end if version_table.tag == "^" then - return false, - err.new("e2 is on a pseudo tag while building in release mode.") + error( + err.new("e2 is on a pseudo tag while building in release mode.")) end end @@ -212,7 +209,7 @@ local function e2_build(arg) for _,r in ipairs(sel_res) do local bid, re = e2tool.buildid(info, r) if not bid then - return false, re + error(re) end end @@ -220,25 +217,21 @@ local function e2_build(arg) for _,r in ipairs(sel_res) do local bid, re = e2tool.buildid(info, r) if not bid then - return false, re + error(re) end console.infof("%-20s [%s]\n", r, bid) end - - return true - end - - -- build - local rc, re = e2build.build_results(info, sel_res) - if not rc then - return false, re + else + -- build + local rc, re = e2build.build_results(info, sel_res) + if not rc then + error(re) + end end - - return true end -local rc, re = e2_build(arg) -if not rc then +local pc, re = pcall(e2_build, arg) +if not pc then e2lib.abort(re) end diff --git a/local/e2-cf.lua b/local/e2-cf.lua index 9e30890..45aec2b 100644 --- a/local/e2-cf.lua +++ b/local/e2-cf.lua @@ -319,29 +319,29 @@ end local function e2_cf(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "cf") if not info then - return false, re + error(re) end local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end -- initialize some basics in the info structure without actually loading -- the project configuration. info, re = e2tool.collect_project_info(info, true) if not info then - return false, re + error(re) end local rc, re = e2lib.chdir(info.root) if not rc then - return false, re + error(re) end commands.editbuildscript = editbuildscript @@ -368,7 +368,7 @@ local function e2_cf(arg) end if #match == 0 then - return false, err.new("unknown command") + error(err.new("unknown command")) elseif #match == 1 then local a = {} for _,o in ipairs(arguments) do @@ -377,18 +377,16 @@ local function e2_cf(arg) local f = commands[match[1]] rc, re = f(info, a) if not rc then - return false, re + error(re) end else - return false, err.new("Ambiguous command: \"%s\" matches: %s", - cmd, table.concat(match, ', ')) + error(err.new("Ambiguous command: \"%s\" matches: %s", + cmd, table.concat(match, ', '))) end - - return true end -local rc, re = e2_cf(arg) -if not rc then +local pc, re = pcall(e2_cf, arg) +if not pc then e2lib.abort(re) end diff --git a/local/e2-dlist.lua b/local/e2-dlist.lua index 5c5e760..f97e2c0 100644 --- a/local/e2-dlist.lua +++ b/local/e2-dlist.lua @@ -37,33 +37,33 @@ local err = require("err") local function e2_dlist(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "dlist") if not info then - return false, re + error(re) end e2option.flag("recursive", "show indirect dependencies, too") local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end if #arguments == 0 then - return false, - err.new("no result given - enter `e2-dlist --help' for usage information") + error(err.new( + "no result given - enter `e2-dlist --help' for usage information")) elseif #arguments ~= 1 then e2option.usage(1) end local result = arguments[1] info, re = e2tool.collect_project_info(info) if not info then - return false, re + error(re) end if not info.results[ result ] then - return false, err.new("no such result: %s", result) + error(err.new("no such result: %s", result)) end local dep, re @@ -73,18 +73,16 @@ local function e2_dlist(arg) dep, re = e2tool.dlist(info, result) end if not dep then - return false, re + error(re) end for _,d in ipairs(dep) do console.infonl(d) end - - return true end -local rc, re = e2_dlist(arg) -if not rc then +local pc, re = pcall(e2_dlist, arg) +if not pc then e2lib.abort(re) end diff --git a/local/e2-dsort.lua b/local/e2-dsort.lua index 8b6dd71..0d73945 100644 --- a/local/e2-dsort.lua +++ b/local/e2-dsort.lua @@ -36,22 +36,22 @@ local e2option = require("e2option") local function e2_dsort(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "dsort") if not info then - return false, re + error(re) end local opts, re = e2option.parse(arg) if not opts then - return false, re + error(re) end info, re = e2tool.collect_project_info(info) if not info then - return false, re + error(re) end local d = e2tool.dsort(info) @@ -60,12 +60,10 @@ local function e2_dsort(arg) console.infonl(dep) end end - - return true end -local rc, re = e2_dsort(arg) -if not rc then +local pc, re = pcall(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 bd66dea..ac9294b 100644 --- a/local/e2-fetch-sources.lua +++ b/local/e2-fetch-sources.lua @@ -40,12 +40,12 @@ local scm = require("scm") local function e2_fetch_source(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "fetch-sources") if not info then - return false, re + error(re) end local e = err.new() @@ -64,12 +64,12 @@ local function e2_fetch_source(arg) local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end info, re = e2tool.collect_project_info(info) if not info then - return false, info + error(re) end if not (opts.fetch or opts.update) then @@ -190,9 +190,9 @@ local function e2_fetch_source(arg) sel[s] = s end elseif opts.result then - return false, err.new("is not a result: %s", x) + error(err.new("is not a result: %s", x)) else - return false, err.new("is not a source: %s", x) + error(err.new("is not a source: %s", x)) end end elseif opts["all"] then @@ -218,7 +218,7 @@ local function e2_fetch_source(arg) end end if e:getcount() > 0 then - return false, e + error(e) end if opts.chroot then @@ -240,14 +240,12 @@ local function e2_fetch_source(arg) end if e:getcount() > 0 then - return false, e + error(e) end - - return true end -local rc, re = e2_fetch_source(arg) -if not rc then +local pc, re = pcall(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 2cb1f2c..432401a 100644 --- a/local/e2-help.lua +++ b/local/e2-help.lua @@ -241,54 +241,52 @@ local function e2_help(arg) local rc, re, e rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "help") if not info then - return false, re; + error(re) end local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end info, re = e2tool.collect_project_info(info, true) if not info then - return false, re + error(re) end local documentation = {} if #arguments == 0 then rc, re = discover_documentation(documentation) if not rc then - return false, re + error(re) end rc, re = list_documentation(documentation) if not rc then - return false, re + error(re) end elseif #arguments == 1 then rc, re = discover_documentation(documentation) if not rc then - return false, re + error(re) end rc, re = display_doc(documentation, arguments[1]) if not rc then - return false, re + error(re) end else - return false, err.new("Too many arguments") + error(err.new("Too many arguments")) end - - return true end -local rc, re = e2_help(arg) -if not rc then +local pc, re = pcall(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 d52b6c8..5fb0f08 100644 --- a/local/e2-ls-project.lua +++ b/local/e2-ls-project.lua @@ -42,12 +42,12 @@ local scm = require("scm") local function e2_ls_project(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "ls-project") if not info then - return false, re + error(re) end policy.register_commandline_options() @@ -58,12 +58,12 @@ local function e2_ls_project(arg) local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end info, re = e2tool.collect_project_info(info) if not info then - return false, re + error(re) end local results = {} @@ -76,19 +76,19 @@ local function e2_ls_project(arg) if info.results[r] then table.insert(results, r) else - return false, err.new("not a result: %s", r) + error(err.new("not a result: %s", r)) end end end if #results > 0 then results, re = e2tool.dlist_recursive(info, results) if not results then - return false, re + error(re) end else results, re = e2tool.dsort(info) if not results then - return false, re + error(re) end end table.sort(results) @@ -326,8 +326,8 @@ local function e2_ls_project(arg) return true end -local rc, re = e2_ls_project(arg) -if not rc then +local pc, re = pcall(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 a49ff58..41b10b9 100644 --- a/local/e2-new-source.lua +++ b/local/e2-new-source.lua @@ -222,12 +222,12 @@ end local function e2_new_source(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "new-source") if not info then - return false, re + error(re) end e2option.flag("git", "create a git repository") @@ -236,17 +236,17 @@ local function e2_new_source(arg) e2option.flag("no-checksum", "do not verify checksum file") local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end info, re = e2tool.collect_project_info(info) if not info then - return false, re + error(re) end if opts.git then if #arguments ~= 1 then - return false, err.new(" argument required") + error(err.new(" argument required")) end -- remote local rserver = info.default_repo_server @@ -261,7 +261,7 @@ local function e2_new_source(arg) local rc, re = generic_git.new_repository(info.cache, lserver, llocation, rserver, rlocation) if not rc then - return false, re + error(re) end e2lib.log(1, "Read e2-new-source(1) for the next step") elseif opts.files then @@ -272,7 +272,7 @@ local function e2_new_source(arg) local location = arguments[1] local sl, re = e2lib.parse_server_location(location, info.default_files_server) if not sl then - return false, re + error(re) end local server = sl.server local location = sl.location @@ -280,23 +280,21 @@ local function e2_new_source(arg) local checksum_file = arguments[3] local verify = not opts["no-checksum"] if verify and not checksum_file then - return false, err.new("checksum file argument missing") + error(err.new("checksum file argument missing")) end local rc, re = new_files_source(info.cache, server, location, source_file, checksum_file, verify) if not rc then - return false, re + error(re) end else - return false, err.new("Please specify either --files are --git") + error(err.new("Please specify either --files are --git")) end - - return true end -local rc, re = e2_new_source(arg) -if not rc then +local pc, re = pcall(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 693470c..69f272f 100644 --- a/local/e2-playground.lua +++ b/local/e2-playground.lua @@ -42,12 +42,12 @@ local policy = require("policy") local function e2_playground(arg) local rc, re = e2lib.init() if not rc then - return false, re + error(re) end local info, re = e2tool.local_init(nil, "playground") if not info then - return false, re + error(re) end local e = err.new("entering playground failed") @@ -59,17 +59,17 @@ local function e2_playground(arg) local opts, arguments = e2option.parse(arg) if not opts then - return false, arguments + error(arguments) end -- get build mode from the command line local build_mode, re = policy.handle_commandline_options(opts, true) if not build_mode then - return false, re + error(re) end info, re = e2tool.collect_project_info(info) if not info then - return false, re + error(re) end if #arguments ~= 1 then @@ -84,10 +84,10 @@ local function e2_playground(arg) end rc, re = e2build.build_config(info, r, {}) if not rc then - return false, e:cat(re) + error(e:cat(re)) end if not e2build.chroot_exists(info, r) then - return false, err.new("playground does not exist") + error(err.new("playground does not exist")) end if opts.showpath then console.infonl(info.results[r].build_config.c) @@ -113,7 +113,7 @@ local function e2_playground(arg) end rc, re = eio.file_write(profile, table.concat(out)) if not rc then - return false, e:cat(re) + error(e:cat(re)) end local command = nil if opts.command then @@ -128,14 +128,12 @@ local function e2_playground(arg) end rc, re = e2build.enter_playground(info, r, command) if not rc then - return false, re + error(re) end - - return true end -local rc, re = e2_playground(arg) -if not rc then +local pc, re = pcall(e2_playground, arg) +if not pc then e2lib.abort(re) end