]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
unify error message format between between C and Lua
authorPetr Špaček <petr.spacek@nic.cz>
Fri, 22 Mar 2019 15:30:17 +0000 (16:30 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Thu, 4 Apr 2019 12:18:59 +0000 (14:18 +0200)
User-friendly error message is intentionally at the end so users,
typically looking at the last line in logs, can see immediatelly what
happened.

daemon/bindings/impl.c
daemon/lua/sandbox.lua.in

index 2db2895d2ffa3499385941bd40121d4f4f559ff1..21a8d7876eea140287fa30b8999fcd189b614e5a 100644 (file)
@@ -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
index 99c9da137fc301984200e42ac3cc3c809784a99b..562d1d7dcdc47006c558774b3fdb8335d24d071d 100644 (file)
@@ -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', ...))