diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2020-12-10 12:15:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-10 12:15:40 +0100 |
commit | 52e660e8570346d28f5c7f5dde0a5ca9b614a801 (patch) | |
tree | e8c812008bf726eeff5519193a633211fd97853f | |
parent | 99007bcc1254717bb7d3803bf4b892a6153bd091 (diff) | |
parent | 3421485253eca065eb9b0a3031228313c278f435 (diff) | |
download | rneovim-52e660e8570346d28f5c7f5dde0a5ca9b614a801.tar.gz rneovim-52e660e8570346d28f5c7f5dde0a5ca9b614a801.tar.bz2 rneovim-52e660e8570346d28f5c7f5dde0a5ca9b614a801.zip |
Merge pull request #13482 from dm1try/propagate_lua_file_loading_errors
runtime: propagate lua parsing errors while using "require"
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/nvim/lua/vim.lua | 6 | ||||
-rw-r--r-- | test/functional/fixtures/lua/syntax_error.lua | 1 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 15 |
4 files changed, 21 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 78588fb3da..0b34639d32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -659,7 +659,7 @@ endif() if(LUACHECK_PRG) add_custom_target(lualint - COMMAND ${LUACHECK_PRG} -q runtime/ src/ test/ + COMMAND ${LUACHECK_PRG} -q runtime/ src/ test/ --exclude-files test/functional/fixtures/lua/syntax_error.lua WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) else() add_custom_target(lualint false diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua index 2c7ab46ffe..b20fbbf038 100644 --- a/src/nvim/lua/vim.lua +++ b/src/nvim/lua/vim.lua @@ -115,7 +115,8 @@ function vim._load_package(name) for _,path in ipairs(paths) do local found = vim.api.nvim_get_runtime_file(path, false) if #found > 0 then - return loadfile(found[1]) + local f, err = loadfile(found[1]) + return f or error(err) end end @@ -123,7 +124,8 @@ function vim._load_package(name) local path = "lua/"..trail:gsub('?',basename) local found = vim.api.nvim_get_runtime_file(path, false) if #found > 0 then - return package.loadlib(found[1]) + local f, err = package.loadlib(found[1]) + return f or error(err) end end return nil diff --git a/test/functional/fixtures/lua/syntax_error.lua b/test/functional/fixtures/lua/syntax_error.lua new file mode 100644 index 0000000000..8c0cf026ee --- /dev/null +++ b/test/functional/fixtures/lua/syntax_error.lua @@ -0,0 +1 @@ +- <= the syntax error diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index e9e1f7ec12..e253db5297 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1453,3 +1453,18 @@ describe('lua stdlib', function() end) end) end) + +describe('lua: require("mod") from packages', function() + before_each(function() + command('set rtp+=test/functional/fixtures') + end) + + it('propagates syntax error', function() + local syntax_error_msg = exec_lua [[ + local _, err = pcall(require, "syntax_error") + return err + ]] + + matches("unexpected symbol", syntax_error_msg) + end) +end) |