From 223ac7782e24c3d662185b5f1fc63d718c4376bc Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 16 Apr 2025 05:06:39 -0700 Subject: [PATCH] fix(vim.system): unclear non-executable message #33455 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: When a command is not found or not executable, the error message gives no indication about what command was actually tried. Solution: Always append the command name to the error message. BEFORE: E5108: Error executing lua …/_system.lua:248: ENOENT: no such file or directory AFTER: E5108: Error executing lua …/_system.lua:249: ENOENT: no such file or directory: "foo" fix #33445 --- runtime/lua/vim/_system.lua | 2 +- test/functional/lua/system_spec.lua | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/_system.lua b/runtime/lua/vim/_system.lua index 157172447a..947aa5c86f 100644 --- a/runtime/lua/vim/_system.lua +++ b/runtime/lua/vim/_system.lua @@ -245,7 +245,7 @@ local function spawn(cmd, opts, on_exit, on_error) local handle, pid_or_err = uv.spawn(cmd, opts, on_exit) if not handle then on_error() - error(pid_or_err) + error(('%s: "%s"'):format(pid_or_err, cmd)) end return handle, pid_or_err --[[@as integer]] end diff --git a/test/functional/lua/system_spec.lua b/test/functional/lua/system_spec.lua index 6c320376c9..5abd901a9d 100644 --- a/test/functional/lua/system_spec.lua +++ b/test/functional/lua/system_spec.lua @@ -53,6 +53,13 @@ describe('vim.system', function() for name, system in pairs { sync = system_sync, async = system_async } do describe('(' .. name .. ')', function() + it('failure modes', function() + t.matches( + 'ENOENT%: no such file .*: "non%-existent%-cmd"', + t.pcall_err(system, { 'non-existent-cmd', 'arg1', 'arg2' }, { text = true }) + ) + end) + it('can run simple commands', function() eq('hello\n', system({ 'echo', 'hello' }, { text = true }).stdout) end)