From: Tobias Ulmer Date: Fri, 25 Jan 2019 16:11:58 +0000 (+0100) Subject: e2lib: if logf() format fails, abort with helpful message X-Git-Tag: e2factory-2.3.18rc1~66 X-Git-Url: https://git.e2factory.org/?a=commitdiff_plain;h=0e16ee4b72669915289d82aedc0ac58e73176500;p=e2factory.git e2lib: if logf() format fails, abort with helpful message Signed-off-by: Tobias Ulmer --- diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 848bc9f..9823787 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -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