Lua: Improve Listener error handling

Fix error handlers in Listener draw() and reset() to avoid getting
LUA_ERRERR from lua_pcall(). Added error handler for Listener draw()
callback.

Handle LUA_ERRERR from lua_pcall() to avoid assert on this.
Changed some capitalized words in various error message.

Closes #16974.
This commit is contained in:
Stig Bjørlykke 2020-10-29 16:01:27 +01:00 committed by AndersBroman
parent 00d45cc71a
commit d104571e8a
4 changed files with 44 additions and 14 deletions

View File

@ -344,7 +344,7 @@ static void iter_table_and_call(lua_State* LS, const gchar* table_name, lua_CFun
static int init_error_handler(lua_State* LS) {
const gchar* error = lua_tostring(LS,1);
report_failure("Lua: Error During execution of Initialization:\n %s",error);
report_failure("Lua: Error during execution of initialization:\n %s",error);
return 0;
}
@ -381,7 +381,7 @@ static void wslua_cleanup_routine(void) {
static int prefs_changed_error_handler(lua_State* LS) {
const gchar* error = lua_tostring(LS,1);
report_failure("Lua: Error During execution of prefs apply callback:\n %s",error);
report_failure("Lua: Error during execution of prefs apply callback:\n %s",error);
return 0;
}

View File

@ -27,7 +27,7 @@ struct _lua_menu_data {
static int menu_cb_error_handler(lua_State* L) {
const gchar* error = lua_tostring(L,1);
report_failure("Lua: Error During execution of Menu Callback:\n %s",error);
report_failure("Lua: Error during execution of Menu callback:\n %s",error);
return 0;
}
@ -53,6 +53,9 @@ static void lua_menu_callback(gpointer data) {
case LUA_ERRMEM:
g_warning("Memory alloc error while calling menu callback");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for menu callback");
break;
default:
g_assert_not_reached();
break;
@ -123,7 +126,7 @@ struct _dlg_cb_data {
static int dlg_cb_error_handler(lua_State* L) {
const gchar* error = lua_tostring(L,1);
report_failure("Lua: Error During execution of dialog callback:\n %s",error);
report_failure("Lua: Error during execution of Dialog callback:\n %s",error);
return 0;
}
@ -153,6 +156,9 @@ static void lua_dialog_cb(gchar** user_input, void* data) {
case LUA_ERRMEM:
g_warning("Memory alloc error while calling dialog callback");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for dialog callback");
break;
default:
g_assert_not_reached();
break;
@ -169,7 +175,7 @@ struct _close_cb_data {
static int text_win_close_cb_error_handler(lua_State* L) {
const gchar* error = lua_tostring(L,1);
report_failure("Lua: Error During execution of TextWindow close callback:\n %s",error);
report_failure("Lua: Error during execution of TextWindow close callback:\n %s",error);
return 0;
}
@ -192,6 +198,9 @@ static void text_win_close_cb(void* data) {
case LUA_ERRMEM:
g_warning("Memory alloc error during execution of TextWindow close callback");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for TextWindow close callback");
break;
default:
break;
}
@ -761,6 +770,9 @@ static gboolean wslua_button_callback(funnel_text_window_t* ws_tw, void* data) {
case LUA_ERRMEM:
g_warning("Memory alloc error while calling button callback");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for button callback");
break;
default:
g_assert_not_reached();
break;

View File

@ -32,8 +32,8 @@ static int tap_packet_cb_error_handler(lua_State* L) {
static int repeated = 0;
static int next = 2;
gchar* where = (lua_pinfo) ?
wmem_strdup_printf(NULL, "Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->num) :
wmem_strdup_printf(NULL, "Lua: Error During execution of Listener Packet Callback") ;
wmem_strdup_printf(NULL, "Lua: on packet %i Error during execution of Listener packet callback",lua_pinfo->num) :
wmem_strdup_printf(NULL, "Lua: Error during execution of Listener packet callback") ;
/* show the error the 1st, 3rd, 5th, 9th, 17th, 33th... time it appears to avoid window flooding */
/* XXX the last series of identical errors won't be shown (the user however gets at least one message) */
@ -75,7 +75,6 @@ static tap_packet_status lua_tap_packet(void *tapdata, packet_info *pinfo, epan_
if (tap->packet_ref == LUA_NOREF) return TAP_PACKET_DONT_REDRAW; /* XXX - report error and return TAP_PACKET_FAILED? */
lua_settop(tap->L,0);
lua_pushcfunction(tap->L,tap_packet_cb_error_handler);
lua_rawgeti(tap->L, LUA_REGISTRYINDEX, tap->packet_ref);
@ -105,6 +104,9 @@ static tap_packet_status lua_tap_packet(void *tapdata, packet_info *pinfo, epan_
g_warning("Memory alloc error while calling listener tap callback packet");
/* XXX - TAP_PACKET_FAILED? */
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for listener tap callback");
break;
default:
g_assert_not_reached();
break;
@ -122,9 +124,9 @@ static tap_packet_status lua_tap_packet(void *tapdata, packet_info *pinfo, epan_
}
static int tap_reset_cb_error_handler(lua_State* L) {
const gchar* error = lua_tostring(L,1);
report_failure("Lua: Error During execution of Listener init Callback:\n %s",error);
return 1;
const gchar* error = lua_tostring(L,1);
report_failure("Lua: Error during execution of Listener reset callback:\n %s",error);
return 0;
}
static void lua_tap_reset(void *tapdata) {
@ -135,7 +137,7 @@ static void lua_tap_reset(void *tapdata) {
lua_pushcfunction(tap->L,tap_reset_cb_error_handler);
lua_rawgeti(tap->L, LUA_REGISTRYINDEX, tap->reset_ref);
switch ( lua_pcall(tap->L,0,0,1) ) {
switch ( lua_pcall(tap->L,0,0,lua_gettop(tap->L)-1) ) {
case 0:
break;
case LUA_ERRRUN:
@ -144,21 +146,31 @@ static void lua_tap_reset(void *tapdata) {
case LUA_ERRMEM:
g_warning("Memory alloc error while calling a listener's init()");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for a listener's init()");
break;
default:
g_assert_not_reached();
break;
}
}
static int tap_draw_cb_error_handler(lua_State* L) {
const gchar* error = lua_tostring(L,1);
report_failure("Lua: Error during execution of Listener draw callback:\n %s",error);
return 0;
}
static void lua_tap_draw(void *tapdata) {
Listener tap = (Listener)tapdata;
const gchar* error;
if (tap->draw_ref == LUA_NOREF) return;
lua_pushcfunction(tap->L,tap_reset_cb_error_handler);
lua_pushcfunction(tap->L,tap_draw_cb_error_handler);
lua_rawgeti(tap->L, LUA_REGISTRYINDEX, tap->draw_ref);
switch ( lua_pcall(tap->L,0,0,1) ) {
switch ( lua_pcall(tap->L,0,0,lua_gettop(tap->L)-1) ) {
case 0:
/* OK */
break;
@ -169,6 +181,9 @@ static void lua_tap_draw(void *tapdata) {
case LUA_ERRMEM:
g_warning("Memory alloc error while calling a listener's draw()");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for a listener's draw()");
break;
default:
g_assert_not_reached();
break;

View File

@ -279,6 +279,9 @@ static void statcmd_init(const char *opt_arg, void* userdata) {
case LUA_ERRMEM:
g_warning("Memory alloc error while calling statcmd callback");
break;
case LUA_ERRERR:
g_warning("Error while running the error handler function for statcmd callback");
break;
default:
g_assert_not_reached();
break;