From 0e16ee4b72669915289d82aedc0ac58e73176500 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Fri, 25 Jan 2019 17:11:58 +0100 Subject: [PATCH] e2lib: if logf() format fails, abort with helpful message Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 -- 2.39.5