]> git.e2factory.org Git - e2factory.git/commitdiff
Rework error handling in parse_e2versionfile()
authorTobias Ulmer <tu@emlix.com>
Thu, 25 Apr 2013 16:47:16 +0000 (18:47 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 13:58:55 +0000 (14:58 +0100)
Remove e2_has_fixed_tag() its return values conflict with error
reporting and we can just inline the single use (minus the messages)

Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
local/e2-build.lua
local/e2tool.lua

index 7e004d6573741859f7a7b3a9c46492e1202816d2..af7afd005345d4f3311ed3371d1816dfcd529ce3 100644 (file)
@@ -1338,24 +1338,39 @@ function e2lib.parse_versionfile(filename)
 end
 
 --- Parse e2version file.
+-- @return Table containing tag and branch. False on error.
+-- @return Error object on failure.
 function e2lib.parse_e2versionfile(filename)
     local f = luafile.open(filename, "r")
     if not f then
-        e2lib.abort("can't open e2version file: " .. filename)
+        return false, err.new("can't open e2version file: %s", filename)
     end
+
     local l = f:readline()
     f:close()
     if not l then
-        e2lib.abort("can't parse e2version file: " .. filename)
+        return false, err.new("can't parse e2version file: %s", filename)
     end
+
     local match = l:gmatch("[^%s]+")
-    local v = {}
-    v.branch = match() or e2lib.abort("invalid branch name `", l, "' in e2 version file ",
-    filename)
-    v.tag = match() or e2lib.abort("invalid tag name `", l, "' in e2 version file ",
-    filename)
-    e2lib.logf(3, "using e2 branch %s tag %s", v.branch, v.tag)
-    return v
+
+    local version_table = {}
+    version_table.branch = match()
+    if not version_table.branch then
+        return false, err.new("invalid branch name `%s' in e2 version file %s",
+            l, filename)
+    end
+
+    version_table.tag = match()
+    if not version_table.tag then
+        return false, err.new("invalid tag name `%s' in e2 version file %s",
+            l, filename)
+    end
+
+    e2lib.logf(3, "using e2 branch %s tag %s",
+        version_table.branch, version_table.tag)
+
+    return strict.lock(version_table)
 end
 
 --- Create a temporary file.
index 0e19c89a744beb675a1d1dfb2124dc6983acb629..5b491a5e80cc116b64e5cb980652db6c23dec081 100644 (file)
@@ -197,8 +197,17 @@ local function e2_build(arg)
         return false, re
     end
 
-    if opts.release and not e2tool.e2_has_fixed_tag(info) then
-        return false, err.new("Failure: e2 is on pseudo tag while building in release mode.")
+    if opts.release then
+        local version_table, re = e2lib.parse_e2versionfile(
+            e2lib.join(info.root, ".e2/e2version"))
+        if not version_table then
+            return false, re
+        end
+
+        if version_table.tag == "^" then
+            return false,
+                err.new("e2 is on a pseudo tag while building in release mode.")
+        end
     end
 
     -- calculate buildids for selected results
index 47cdfb233189f4052ad2097f54949c584f6aa7f1..f8346f7f51b895df7a0b3ce3d4aa14e9c9f81240 100644 (file)
@@ -1232,7 +1232,11 @@ function e2tool.collect_project_info(info, skip_load_config)
 
     if e2option.opts["check"] then
         local f = ".e2/e2version"
-        local v = e2lib.parse_e2versionfile(f)
+        local v, re = e2lib.parse_e2versionfile(f)
+        if not v then
+            return false, re
+        end
+
         if v.tag == "^" then
             return false, err.new("local tool version is not configured to " ..
                 "a fixed tag\nfix you configuration in %s before running " ..
@@ -1883,21 +1887,6 @@ local function projid(info)
     return info.projid
 end
 
---- Check if e2 is in a fixed tag.
---
---   e2tool.e2_has_fixed_tag(info)
---
---     return true if e2 is at fixed tag, and false if not.
-function e2tool.e2_has_fixed_tag(info)
-    local v = e2lib.parse_e2versionfile(info.root .. "/.e2/e2version")
-    e2lib.log(2, "Checking for fixed e2 tag.")
-    if v.tag == "^" then
-        e2lib.log(1, "Fatal: e2 is not at a fixed tag.")
-        return false
-    end
-    return true
-end
-
 --- hashcache write.
 local function hashcache_write(info)
     local e = err.new("writing hash cache file")