From 7e07efaff429d8d8634fd059c6295c7ff0b56c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Linse?= Date: Mon, 2 Sep 2019 21:59:58 +0200 Subject: [PATCH] api: make try_end clean-up after an exception properly. Fixes #10809 Otherwise `force_abort` will cause an emsg() higher on the stack to be converted to an exception, even though it is outside any try/catch. --- src/nvim/api/private/helpers.c | 1 + .../functional/lua/utility_functions_spec.lua | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 26f388ae7e..fb3a73ad4a 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -125,6 +125,7 @@ bool try_end(Error *err) // Set by emsg(), affects aborting(). See also enter_cleanup(). did_emsg = false; + force_abort = false; if (got_int) { if (current_exception) { diff --git a/test/functional/lua/utility_functions_spec.lua b/test/functional/lua/utility_functions_spec.lua index 0d93914119..ff15ebf8b3 100644 --- a/test/functional/lua/utility_functions_spec.lua +++ b/test/functional/lua/utility_functions_spec.lua @@ -1,5 +1,6 @@ -- Test suite for testing interactions with API bindings local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local funcs = helpers.funcs local clear = helpers.clear @@ -160,6 +161,37 @@ describe('lua function', function() feed("") eq('Error executing vim.schedule lua callback: [string ""]:2: big failure\nvery async', eval("v:errmsg")) + + local screen = Screen.new(60,5) + screen:set_default_attr_ids({ + [1] = {bold = true, foreground = Screen.colors.Blue1}, + [2] = {bold = true, reverse = true}, + [3] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red}, + [4] = {bold = true, foreground = Screen.colors.SeaGreen4}, + }) + screen:attach() + screen:expect{grid=[[ + ^ | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]]} + + -- nvim_command causes a vimL exception, check that it is properly caught + -- and propagated as an error message in async contexts.. #10809 + exec_lua([[ + vim.schedule(function() + vim.api.nvim_command(":echo 'err") + end) + ]]) + screen:expect{grid=[[ + | + {2: }| + {3:Error executing vim.schedule lua callback: [string ""]}| + {3::2: Vim(echo):E115: Missing quote: 'err} | + {4:Press ENTER or type command to continue}^ | + ]]} end) it("vim.split", function()