From 398201cfabaef47aa93c8a485336a00ef075ad3e Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Sun, 19 Jul 2020 17:16:48 -0400 Subject: lua: Fix crash on unprotected lua errors (#12658) Can be reproduced with a script like this: -- in some lua file vim.fn.timer_start(10, function() error("uh....") end) -- will cause neovim to crash with the following error. PANIC: unprotected error in call to Lua API (nlua_CFunction_func_call failed.) After this, it will instead print the error message from the top of the stack, like so. tmp/error_nvim.lua:10: uh... Also added an example test. Previously this test caused the embedded nvim to panic. --- test/functional/lua/luaeval_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/lua/luaeval_spec.lua') diff --git a/test/functional/lua/luaeval_spec.lua b/test/functional/lua/luaeval_spec.lua index 964ea4561e..75966393b1 100644 --- a/test/functional/lua/luaeval_spec.lua +++ b/test/functional/lua/luaeval_spec.lua @@ -255,6 +255,18 @@ describe('luaeval()', function() ]]) end) + it('can handle functions with errors', function() + eq(true, exec_lua [[ + vim.fn.timer_start(10, function() + error("dead function") + end) + + vim.wait(1000, function() return false end) + + return true + ]]) + end) + it('should handle passing functions around', function() command [[ function VimCanCallLuaCallbacks(Concat, Cb) -- cgit