From db5cc77a140d9a1efc0a5183118858617d044be3 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Thu, 25 Apr 2013 16:27:51 +0200 Subject: [PATCH] Add error handling to e2lib.get_global_config() Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 19 +++++++++++++++---- global/e2-fetch-project.lua | 5 ++++- global/e2-install-e2.lua | 6 +++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 2183326..7e004d6 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -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) diff --git a/global/e2-fetch-project.lua b/global/e2-fetch-project.lua index 64c64e6..ed90ace 100644 --- a/global/e2-fetch-project.lua +++ b/global/e2-fetch-project.lua @@ -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() diff --git a/global/e2-install-e2.lua b/global/e2-install-e2.lua index a648d03..a404d34 100644 --- a/global/e2-install-e2.lua +++ b/global/e2-install-e2.lua @@ -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") -- 2.39.5