From 3a8111e1c2adcdc0603993c6ed5d20a40f162125 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 4 Aug 2020 02:18:22 -0700 Subject: [PATCH] Lua: give better errors for more WTAP_ERR_ types from wtap_dump_open(). Change-Id: I9878baebb78a36f306ae87b802680dc35875e862 Reviewed-on: https://code.wireshark.org/review/38041 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- epan/wslua/wslua_dumper.c | 64 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index c6b3801d42..a7ad5c513f 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -213,6 +213,16 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) { if (! d ) { /* WSLUA_ERROR("Error while opening file for writing"); */ switch (err) { + case WTAP_ERR_NOT_REGULAR_FILE: + luaL_error(L,"The file \"%s\" is a \"special file\" or socket or other non-regular file", + filename); + break; + + case WTAP_ERR_CANT_WRITE_TO_PIPE: + luaL_error(L,"The file \"%s\" is a pipe, and %s capture files can't be written to a pipe", + filename, wtap_file_type_subtype_string(filetype)); + break; + case WTAP_ERR_UNWRITABLE_FILE_TYPE: luaL_error(L,"Files of file type %s cannot be written", wtap_file_type_subtype_string(filetype)); @@ -224,8 +234,28 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) { wtap_encap_name(encap)); break; + case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED: + luaL_error(L,"Files of file type %s don't support per-packet encapsulation", + wtap_file_type_subtype_string(filetype)); + break; + + case WTAP_ERR_CANT_OPEN: + luaL_error(L,"The file \"%s\" could not be created for some unknown reason", + filename); + break; + + case WTAP_ERR_SHORT_WRITE: + luaL_error(L,"A full header couldn't be written to the file \"%s\".", + filename); + break; + + case WTAP_ERR_COMPRESSION_NOT_SUPPORTED: + luaL_error(L,"Files of file type %s cannot be written as a compressed file", + wtap_file_type_subtype_string(filetype)); + break; + default: - luaL_error(L,"error while opening `%s': %s", + luaL_error(L,"error while opening \"%s\": %s", filename, wtap_strerror(err)); break; @@ -376,6 +406,16 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { if (! d ) { switch (err) { + case WTAP_ERR_NOT_REGULAR_FILE: + luaL_error(L,"The file \"%s\" is a \"special file\" or socket or other non-regular file", + filename); + break; + + case WTAP_ERR_CANT_WRITE_TO_PIPE: + luaL_error(L,"The file \"%s\" is a pipe, and %s capture files can't be written to a pipe", + filename, wtap_file_type_subtype_string(filetype)); + break; + case WTAP_ERR_UNWRITABLE_FILE_TYPE: luaL_error(L,"Files of file type %s cannot be written", wtap_file_type_subtype_string(filetype)); @@ -387,8 +427,28 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) { wtap_encap_name(encap)); break; + case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED: + luaL_error(L,"Files of file type %s don't support per-packet encapsulation", + wtap_file_type_subtype_string(filetype)); + break; + + case WTAP_ERR_CANT_OPEN: + luaL_error(L,"The file \"%s\" could not be created for some unknown reason", + filename); + break; + + case WTAP_ERR_SHORT_WRITE: + luaL_error(L,"A full header couldn't be written to the file \"%s\".", + filename); + break; + + case WTAP_ERR_COMPRESSION_NOT_SUPPORTED: + luaL_error(L,"Files of file type %s cannot be written as a compressed file", + wtap_file_type_subtype_string(filetype)); + break; + default: - luaL_error(L,"error while opening `%s': %s", + luaL_error(L,"error while opening \"%s\": %s", filename, wtap_strerror(err)); break;