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 <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
This commit is contained in:
Guy Harris 2020-08-04 02:18:22 -07:00
parent e1c10c5856
commit 3a8111e1c2
1 changed files with 62 additions and 2 deletions

View File

@ -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;