]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib.init() can now return errors
authorTobias Ulmer <tu@emlix.com>
Wed, 24 Apr 2013 15:44:45 +0000 (17:44 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 13:58:55 +0000 (14:58 +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 3a25892980b57b1ae23360664cf4d884b062631d..76e60629c03d9f9196d002efb59f06341dcd2599 100644 (file)
@@ -126,8 +126,9 @@ function e2lib.interrupt_hook()
 end
 
 --- Make sure the environment variables inside the globals table are
--- initialized properly, and abort otherwise.
--- This function always succeeds or aborts.
+-- initialized properly.
+-- @return True on success, false on error.
+-- @return Error object on failure.
 function e2lib.init()
     e2lib.log(4, "e2lib.init()")
     -- DEBUG: change to "cr" to log return from function
@@ -194,7 +195,7 @@ function e2lib.init()
     for _, var in pairs(getenv) do
         var.val = os.getenv(var.name)
         if var.required and not var.val then
-            e2lib.abort(string.format("%s is not set in the environment", var.name))
+            return false, err.new("%s is not set in the environment", var.name)
         end
         if var.default and not var.val then
             var.val = var.default
@@ -216,16 +217,18 @@ function e2lib.init()
     -- get the host name
     local hostname = io.popen("hostname")
     if not hostname then
-        e2lib.abort("execution of \"hostname\" failed")
+        return false, err.new("execution of \"hostname\" failed")
     end
 
     e2lib.globals.hostname = hostname:read("*a")
     hostname:close()
     if not e2lib.globals.hostname then
-        e2lib.abort("hostname ist not set")
+        return false, err.new("hostname ist not set")
     end
 
     e2lib.globals.lock = lock.new()
+
+    return true
 end
 
 --- init2.
index d3f3c09477a1e7e59947da2e7ffc37a620861b45..04db30d53204c1a62100413bdca7bdb6c0a3c03b 100644 (file)
@@ -36,7 +36,10 @@ local e2option = require("e2option")
 require("buildconfig")
 
 local function e2_create_project(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
 
     local opts, arguments = e2option.parse(arg)
     if not opts then
index 6d8db9dd1393fc168687aa60e44ca0903420a049..c5e97a30d6190e00396b6eb62f13c3029758a495 100644 (file)
@@ -36,7 +36,10 @@ local err = require("err")
 require("buildconfig")
 
 local function e2_fetch_project(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
 
     local e = err.new("fetching project failed")
     e2option.option("branch", "retrieve a specific project branch")
index 39607511ef489609ef657eca368bddbc1c80fd54..4e13f6947017a3af5279069c4ffae02bc21e7038 100644 (file)
@@ -35,7 +35,10 @@ local err = require("err")
 require("buildconfig")
 
 local function e2_install_e2(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
 
     local opts, arguments = e2option.parse(arg)
     if not opts then
index 24b6dd2ae8a21d13de46b24111d2a562825c3ba6..6dd4cca86e7fad4898a5c75f964c5b7f056708e0 100644 (file)
@@ -35,7 +35,10 @@ require("buildconfig")
 require("e2util")
 
 local function e2(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
 
     e2option.flag("prefix", "print installation prefix",
     function()
index 8228ab2c562e9e30f228b1d1e7a37416b66b2ff8..3b21ad7c5c70fd974c28db429fe72a322a0486b1 100644 (file)
@@ -32,7 +32,11 @@ local e2tool = require("e2tool")
 local err = require("err")
 
 local function e2_build_numbers(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "build-numbers")
     if not info then
         return false, re
index 08739bb9ff33e5c517741314f6e4708ee3c863c2..0e19c89a744beb675a1d1dfb2124dc6983acb629 100644 (file)
@@ -37,7 +37,11 @@ local scm = require("scm")
 local policy = require("policy")
 
 local function e2_build(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "build")
     if not info then
         return false, re
index ac60d1e14ab9543e1f213bc1d1f9cf69ee9205d1..669afeb5b7d0b58a49114f7f3d853a4dace73afd 100644 (file)
@@ -317,7 +317,11 @@ local function editbuildscript(info, ...)
 end
 
 local function e2_cf(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "cf")
     if not info then
         return false, re
index d64672f70898601a1dfe1a6f0b8cf56edaf1602d..de7b7f765fc9ccd46d8b09fe430ef42365b03e86 100644 (file)
@@ -33,7 +33,11 @@ local e2tool = require("e2tool")
 local e2option = require("e2option")
 
 local function e2_dlist(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "dlist")
     if not info then
         return false, re
index 7aee7992184b74166960b0bc84d2c6682aa20e9d..c2b9f833f9d283059b008a49f621cfba8adb098b 100644 (file)
@@ -33,7 +33,11 @@ local e2tool = require("e2tool")
 local e2option = require("e2option")
 
 local function e2_dsort(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "dsort")
     if not info then
         return false, re
index 6168355b593bd487b2475fb85334998b69228e19..7fa37b3a88466b93b10700cd064aea0a708c4fa9 100644 (file)
@@ -37,7 +37,11 @@ local e2option = require("e2option")
 local scm = require("scm")
 
 local function e2_fetch_source(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "fetch-sources")
     if not info then
         return false, re
index 0b2dcaab4178c4b81b2b335c70fc89ffd51e56c5..cf9c25a7c97fdd4c7a0ebb1ebb73392388c14524 100644 (file)
@@ -232,7 +232,10 @@ end
 -- @return Error object on failure.
 local function e2_help(arg)
     local rc, re, e
-    e2lib.init()
+    rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
 
     local info, re = e2tool.local_init(nil, "help")
     if not info then
index 4cd9d76b10a790ebaae8a364a761ae4adc5ca703..dc8f2713c41f0e2118cb39a47c0aab6a63ca7d06 100644 (file)
@@ -38,7 +38,11 @@ local scm = require("scm")
 local policy = require("policy")
 
 local function e2_ls_project(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "ls-project")
     if not info then
         return false, re
index 181a3231b27e2056436ef26f186ad985fb5b5e8a..8d4619577e07f898a5acdf29fda96e60c3361c99 100644 (file)
@@ -212,7 +212,11 @@ local function new_files_source(c, server, location, source_file, checksum_file,
 end
 
 local function e2_new_source(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "new-source")
     if not info then
         return false, re
index b5ad2d567f6be7caef47b00d89fa6f049c7b7075..eaeae930623a42cd71f464dd5682adb2339afd3c 100644 (file)
@@ -38,7 +38,11 @@ local e2option = require("e2option")
 local policy = require("policy")
 
 local function e2_playground(arg)
-    e2lib.init()
+    local rc, re = e2lib.init()
+    if not rc then
+        return false, re
+    end
+
     local info, re = e2tool.local_init(nil, "playground")
     if not info then
         return false, re