]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib: if logf() format fails, abort with helpful message
authorTobias Ulmer <tu@emlix.com>
Fri, 25 Jan 2019 16:11:58 +0000 (17:11 +0100)
committerTobias Ulmer <tu@emlix.com>
Fri, 25 Jan 2019 16:11:58 +0000 (17:11 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua

index 848bc9f4d1fa3dfd5418d82d3db201d6af33ed54..9823787cd841443ed9fcd3bcfd906849abf51834 100644 (file)
@@ -588,10 +588,16 @@ end
 -- @param ... additional parameters to pass to string.format
 -- @return nil
 function e2lib.logf(level, format, ...)
-    if not format then
-        e2lib.log(1, "Internal error: calling logf() without format string")
+    if type(format) ~= "string" then
+        e2lib.log(1, "Internal error: calling logf() without valid format string")
+    end
+    local status, msg = pcall(string.format, format, ...)
+    if not status then
+        e2lib.abort("failed to format log message\n",
+            "  error message: ", msg, "\n",
+            "  format string: ", format, "\n",
+            "  ", debug.traceback())
     end
-    local msg = string.format(format, ...)
     return e2lib.log(level, msg)
 end