]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix type check error message
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 11 Sep 2018 13:42:06 +0000 (14:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 11 Sep 2018 13:42:06 +0000 (14:42 +0100)
src/lua/lua_common.c

index 92c9d0b618fab4319006d826cc75c50580a91fa4..ac7a393b8779554d460307e8a4d2290d5c384a69 100644 (file)
@@ -1569,19 +1569,19 @@ err:
        if (fatal) {
                const gchar *actual_classname = NULL;
 
-               if (lua_getmetatable (L, pos)) {
+               if (lua_type (L, pos) == LUA_TUSERDATA && lua_getmetatable (L, pos)) {
                        lua_pushstring (L, "__index");
-                       lua_gettable (L, -3);
+                       lua_gettable (L, -2);
                        lua_pushstring (L, "class");
                        lua_gettable (L, -2);
                        actual_classname = lua_tostring (L, -1);
                }
                else {
-                       actual_classname = lua_typename (L, lua_type (L, -1));
+                       actual_classname = lua_typename (L, lua_type (L, pos));
                }
 
                err_msg = g_string_sized_new (100);
-               rspamd_printf_gstring (err_msg, "expected %s at %d, but userdata has "
+               rspamd_printf_gstring (err_msg, "expected %s at position %d, but userdata has "
                                                                                "%s metatable; trace: ",
                                classname, pos, actual_classname);
                rspamd_lua_traceback_string (L, err_msg);
@@ -1589,15 +1589,21 @@ err:
 
                for (i = 1; i <= MIN (top, 10); i ++) {
                        if (lua_type (L, i) == LUA_TUSERDATA) {
-                               lua_getmetatable (L, i);
-                               lua_pushstring (L, "__index");
-                               lua_gettable (L, -3);
-                               lua_pushstring (L, "class");
-                               lua_gettable (L, -2);
+                               const char *clsname;
+
+                               if (lua_getmetatable (L, i)) {
+                                       lua_pushstring (L, "__index");
+                                       lua_gettable (L, -2);
+                                       lua_pushstring (L, "class");
+                                       lua_gettable (L, -2);
+                                       clsname = lua_tostring (L, -1);
+                               }
+                               else {
+                                       clsname = lua_typename (L, lua_type (L, i));
+                               }
 
                                rspamd_printf_gstring (err_msg, "[%d: ud=%s] ", i,
-                                               lua_tostring (L, -1));
-                               lua_pop (L, 3);
+                                               clsname);
                        }
                        else {
                                rspamd_printf_gstring (err_msg, "[%d: %s] ", i,