]> git.e2factory.org Git - e2factory.git/commitdiff
Modify callcmd_log() to return an error object
authorTobias Ulmer <tu@emlix.com>
Thu, 11 Jul 2013 10:50:29 +0000 (12:50 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:01:23 +0000 (15:01 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
global/e2-fetch-project.lua

index 74deb7496d616907b7f34ad7e89bf7a518577ae7..a2a0848089e4871d59e94eaee02996e7f87945b6 100644 (file)
@@ -1191,22 +1191,35 @@ function e2lib.callcmd_capture(cmd, capture)
     return rc
 end
 
---- call a command, log its output to a loglevel, catch the last line of
--- output and return it in addition to the commands return code
+--- Call a command, log its output and catch the last lines for error reporting.
 -- @param cmd string: the command
--- @param loglevel number: loglevel (optional, defaults to 3)
--- @return number: the return code
--- @return string: the program output, or nil
-function e2lib.callcmd_log(cmd, loglevel)
-    local e = ""
-    if not loglevel then
-        loglevel = 3
-    end
-    local function logto(output)
-        e2lib.log(loglevel, output)
-        e = e .. output
+-- @return Return code of the command (number).
+-- @return Error object containing command line and last lines of output.
+function e2lib.callcmd_log(cmd)
+    local e = err.new("command %s failed:", cmd)
+    local fifo = {}
+
+    local function logto(msg)
+        e2lib.log(3, msg)
+
+        if msg ~= "" then
+            if #fifo > 4 then -- keep the last n lines.
+                table.remove(fifo, 1)
+            end
+            table.insert(fifo, msg)
+        end
     end
+
     local rc = e2lib.callcmd_capture(cmd, logto)
+
+    if #fifo == 0 then
+        table.insert(fifo, "command failed silently, no output captured")
+    end
+
+    for _,v in ipairs(fifo) do
+        e:append("%s", v)
+    end
+
     return rc, e
 end
 
@@ -1555,7 +1568,7 @@ function e2lib.call_tool(tool, args)
     if rc ~= 0 then
         return false, e
     end
-    return true, e
+    return true
 end
 
 --- call a tool with argv
@@ -1616,7 +1629,7 @@ function e2lib.call_tool_argv_capture(tool, argv, capturefn)
     if rc ~= 0 then
         return false, e
     end
-    return true, e
+    return true
 end
 
 --- call git
@@ -1643,7 +1656,6 @@ function e2lib.git(gitdir, subtool, args)
     e2lib.shquote(gitdir), e2lib.shquote(git), e2lib.shquote(subtool), args)
     rc, re = e2lib.callcmd_log(call)
     if rc ~= 0 then
-        e:append(call)
         return false, e:cat(re)
     end
     return true, e
index ef3dcaa875878a674cfcb122d3be33d807ca1d20..0744cc23fe33a1642e35947d765594f1c627303e 100644 (file)
@@ -196,7 +196,8 @@ local function e2_fetch_project(arg)
     e2lib.shquote(buildconfig.LUA), e2lib.shquote(buildconfig.TOOLDIR))
     rc, re = e2lib.callcmd_log(e2_install_e2)
     if rc ~= 0 then
-        return false, err.new("installing local e2 failed")
+        local e = err.new("installing local e2 failed")
+        return false, e:cat(re)
     end
 
     return true