]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Improve logging
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 Nov 2019 16:30:34 +0000 (16:30 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 26 Nov 2019 16:30:34 +0000 (16:30 +0000)
src/lua/lua_common.c
src/lua/lua_text.c

index 45ca2c97e0576dce2de7bb7bc2a0f0bab8aa92c2..f5cd3b8536e78b52688148747d6a2258621c3467 100644 (file)
@@ -2112,11 +2112,14 @@ gboolean
 rspamd_lua_require_function (lua_State *L, const gchar *modname,
                const gchar *funcname)
 {
-       gint table_pos;
+       gint table_pos, err_pos;
 
+       lua_pushcfunction (L, &rspamd_lua_traceback);
+       err_pos = lua_gettop (L);
        lua_getglobal (L, "require");
 
        if (lua_isnil (L, -1)) {
+               lua_remove (L, err_pos);
                lua_pop (L, 1);
 
                return FALSE;
@@ -2126,13 +2129,21 @@ rspamd_lua_require_function (lua_State *L, const gchar *modname,
 
        /* Now try to call */
        if (lua_pcall (L, 1, 1, 0) != 0) {
+               lua_remove (L, err_pos);
+               msg_warn ("require of %s.%s failed: %s", modname,
+                               funcname, lua_tostring (L, -1));
                lua_pop (L, 1);
 
                return FALSE;
        }
 
+       lua_remove (L, err_pos);
+
        /* Now we should have a table with results */
        if (!lua_istable (L, -1)) {
+               msg_warn ("require of %s.%s failed: not a table but %s", modname,
+                               funcname, lua_typename (L, lua_type (L, -1)));
+
                lua_pop (L, 1);
 
                return FALSE;
@@ -2148,6 +2159,10 @@ rspamd_lua_require_function (lua_State *L, const gchar *modname,
 
                return TRUE;
        }
+       else {
+               msg_warn ("require of %s.%s failed: not a function but %s", modname,
+                               funcname, lua_typename (L, lua_type (L, -1)));
+       }
 
        lua_pop (L, 2);
 
index 09d9b88c1eddad9b4d4df75c42e1a2cc4f63a94c..55dcb8a8898168dd5f1110ad072a24489fef97d9 100644 (file)
@@ -355,7 +355,7 @@ lua_text_span (lua_State *L)
 {
        LUA_TRACE_POINT;
        struct rspamd_lua_text *t = lua_check_text (L, 1);
-       gint start = lua_tointeger (L, 2), len = -1;
+       gint64 start = lua_tointeger (L, 2), len = -1;
 
        if (t && start >= 1 && start <= t->len) {
                if (lua_isnumber (L, 3)) {
@@ -372,7 +372,13 @@ lua_text_span (lua_State *L)
                lua_new_text (L, t->start + (start - 1), len, FALSE);
        }
        else {
-               return luaL_error (L, "invalid arguments");
+               if (!t) {
+                       return luaL_error (L, "invalid arguments, text required");
+               }
+               else {
+                       return luaL_error (L, "invalid arguments: start offset %d "
+                                                "is larger than text len %d", (int)start, (int)t->len);
+               }
        }
 
        return 1;