From: Petr Špaček Date: Fri, 22 Mar 2019 15:30:17 +0000 (+0100) Subject: unify error message format between between C and Lua X-Git-Tag: v4.0.0~15^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2efa642b53de8ffe81b55275c0fbf7f7baf2558b;p=thirdparty%2Fknot-resolver.git unify error message format between between C and Lua User-friendly error message is intentionally at the end so users, typically looking at the last line in logs, can see immediatelly what happened. --- diff --git a/daemon/bindings/impl.c b/daemon/bindings/impl.c index 2db2895d2..21a8d7876 100644 --- a/daemon/bindings/impl.c +++ b/daemon/bindings/impl.c @@ -71,17 +71,17 @@ void kr_bindings_register(lua_State *L) void lua_error_p(lua_State *L, const char *fmt, ...) { + /* Add a stack trace and throw the result as a lua error. */ + luaL_traceback(L, L, "error occured here (config filename:lineno is at the bottom, if config is involved):", 0); /* Push formatted custom message, prepended with "ERROR: ". */ - lua_pushliteral(L, "ERROR: "); + lua_pushliteral(L, "\nERROR: "); { va_list args; va_start(args, fmt); lua_pushvfstring(L, fmt, args); va_end(args); } - lua_concat(L, 2); - /* Add a stack trace and throw the result as a lua error. */ - luaL_traceback(L, L, lua_tostring(L, -1), 0); + lua_concat(L, 3); lua_error(L); /* TODO: we might construct a little more friendly trace by using luaL_where(). * In particular, in case the error happens in a function that was called diff --git a/daemon/lua/sandbox.lua.in b/daemon/lua/sandbox.lua.in index 99c9da137..562d1d7dc 100644 --- a/daemon/lua/sandbox.lua.in +++ b/daemon/lua/sandbox.lua.in @@ -1,3 +1,4 @@ +local debug = require('debug') local ffi = require('ffi') -- Units @@ -14,7 +15,9 @@ day = 24 * hour -- Logging function panic(fmt, ...) - error(string.format('error: '..fmt, ...)) + print(debug.traceback('error occured here (config filename:lineno is ' + .. 'at the bottom, if config is involved):', 2)) + error(string.format('ERROR: '.. fmt, ...), 0) end function warn(fmt, ...) io.stderr:write(string.format(fmt..'\n', ...))