diff --git a/spawn.c b/spawn.c index f65c68d6..3e89ca23 100644 --- a/spawn.c +++ b/spawn.c @@ -414,11 +414,11 @@ luaA_spawn(lua_State *L) { g_strfreev(argv); if (error) { - luaA_warn(L, "spawn: parse error: %s", error->message); + lua_pushfstring(L, "spawn: parse error: %s", error->message); g_error_free(error); } else - luaA_warn(L, "spawn: There is nothing to execute"); + lua_pushliteral(L, "spawn: There is nothing to execute"); return 1; } @@ -443,7 +443,7 @@ luaA_spawn(lua_State *L) g_strfreev(argv); if(!retval) { - luaA_warn(L, "%s", error->message); + lua_pushstring(L, error->message); g_error_free(error); if(context) sn_launcher_context_complete(context); diff --git a/tests/test-spawn.lua b/tests/test-spawn.lua index 0a79a9c2..b06249a0 100644 --- a/tests/test-spawn.lua +++ b/tests/test-spawn.lua @@ -10,6 +10,31 @@ local exit_yay, exit_snd = nil, nil -- * spawn with startup notification is covered by test-spawn-snid.lua local steps = { + function() + -- Test various error conditions. There are quite a number of them... + local error_message + + error_message = spawn("this_does_not_exist_and_should_fail") + assert(string.find(error_message, 'No such file or directory'), error_message) + + error_message = spawn({"this_does_not_exist_and_should_fail"}) + assert(string.find(error_message, 'No such file or directory'), error_message) + + error_message = spawn("foo '") + assert(string.find(error_message, 'parse error: Text ended before matching quote was found'), error_message) + + error_message = spawn() + assert(string.find(error_message, 'No command to execute'), error_message) + + error_message = spawn(" ") + assert(string.find(error_message, 'Text was empty'), error_message) + + error_message = spawn{} + assert(string.find(error_message, 'There is nothing to execute'), error_message) + + return true + end, + function(count) if count == 1 then local steps_yay = 0