]> git.e2factory.org Git - e2factory.git/commitdiff
Add error handling to e2lib.get_global_config()
authorTobias Ulmer <tu@emlix.com>
Thu, 25 Apr 2013 14:27:51 +0000 (16:27 +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>
generic/e2lib.lua
global/e2-fetch-project.lua
global/e2-install-e2.lua

index 2183326a53704a53a411e82dcb622b8f360a065b..7e004d6573741859f7a7b3a9c46492e1202816d2 100644 (file)
@@ -239,7 +239,10 @@ function e2lib.init2()
     local e = err.new("initializing globals (step2)")
 
     -- get the global configuration
-    local config = e2lib.get_global_config()
+    local config, re = e2lib.get_global_config()
+    if not config then
+        return false, re
+    end
 
     -- honour tool customizations from the config file
     if config.tools then
@@ -934,12 +937,14 @@ end
 
 --- get the global configuration
 -- this function always succeeds or aborts
--- @return the global configuration
+-- @return The global configuration, or false on error.
+-- @return Error object on failure.
 function e2lib.get_global_config()
     local config = global_config
     if not config then
-        e2lib.abort("global config not available")
+        return false, err.new("global config not available")
     end
+
     return config
 end
 
@@ -1962,10 +1967,16 @@ end
 -- @return an error object on failure
 function e2lib.setup_cache()
     local e = err.new("setting up cache failed")
-    local config = e2lib.get_global_config()
+
+    local config, re = e2lib.get_global_config()
+    if not config then
+        return false, re
+    end
+
     if type(config.cache) ~= "table" or type(config.cache.path) ~= "string" then
         return false, e:append("invalid cache configuration: config.cache.path")
     end
+
     local replace = { u=e2lib.globals.username }
     local cache_path = e2lib.format_replace(config.cache.path, replace)
     local cache_url = string.format("file://%s", cache_path)
index 64c64e66d2be690301a4a71f5dd6f1659ef27758..ed90ace511e5f4620d60decf613c65f5c3d7489f 100644 (file)
@@ -61,7 +61,10 @@ local function e2_fetch_project(arg)
     end
 
     -- get the global configuration
-    local config = e2lib.get_global_config()
+    local config, re = e2lib.get_global_config()
+    if not config then
+        return false, e:cat(re)
+    end
 
     -- setup cache
     local scache, re = e2lib.setup_cache()
index a648d03f1c61a1a86d7663fe5a25ab06f324683d..a404d3423528dd29261477c79d40ff80dd546275 100644 (file)
@@ -67,7 +67,11 @@ local function e2_install_e2(arg)
 
     local e = err.new("e2-install-e2 failed")
 
-    local config = e2lib.get_global_config()
+    local config, re = e2lib.get_global_config()
+    if not config then
+        return false, re
+    end
+
     local servers = config.servers
     if not servers then
         return false, err.new("no servers configured in global config")