diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-09-23 15:59:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-23 15:59:37 +0800 |
commit | 5331d5772ffbbdb3635d0a4b41306817097e86de (patch) | |
tree | 259eea5584b6e0aa2452da474db434eda521cc08 | |
parent | c0a29931e29bbb40650df01918826cdb64e8fc32 (diff) | |
download | rneovim-5331d5772ffbbdb3635d0a4b41306817097e86de.tar.gz rneovim-5331d5772ffbbdb3635d0a4b41306817097e86de.tar.bz2 rneovim-5331d5772ffbbdb3635d0a4b41306817097e86de.zip |
fix(lua): show error message when failing to set variable (#25321)
-rw-r--r-- | src/nvim/lua/stdlib.c | 3 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 2 |
3 files changed, 8 insertions, 0 deletions
diff --git a/src/nvim/lua/stdlib.c b/src/nvim/lua/stdlib.c index 4f9677650f..8f1b5c7b86 100644 --- a/src/nvim/lua/stdlib.c +++ b/src/nvim/lua/stdlib.c @@ -359,6 +359,9 @@ int nlua_setvar(lua_State *lstate) Error err = ERROR_INIT; dictitem_T *di = dict_check_writable(dict, key, del, &err); if (ERROR_SET(&err)) { + nlua_push_errstr(lstate, "%s", err.msg); + api_clear_error(&err); + lua_error(lstate); return 0; } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index f734bfb0c0..fcf3eae5ec 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1353,6 +1353,9 @@ describe('API', function() -- Set readonly v: var. eq('Key is read-only: count', pcall_err(request, 'nvim_set_vvar', 'count', 42)) + -- Set non-existent v: var. + eq('Dictionary is locked', + pcall_err(request, 'nvim_set_vvar', 'nosuchvar', 42)) -- Set writable v: var. meths.set_vvar('errmsg', 'set by API') eq('set by API', meths.get_vvar('errmsg')) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 1dfb9a5e10..cf80478b08 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1491,6 +1491,8 @@ describe('lua stdlib', function() eq(NIL, funcs.luaeval "vim.v.null") matches([[attempt to index .* nil value]], pcall_err(exec_lua, 'return vim.v[0].progpath')) + eq('Key is read-only: count', pcall_err(exec_lua, 'vim.v.count = 42')) + eq('Dictionary is locked', pcall_err(exec_lua, 'vim.v.nosuchvar = 42')) end) it('vim.bo', function() |