Skip to content

Commit df98bfb

Browse files
committed
fix(server): error correctly when no processes found on Unix
#201
1 parent c451511 commit df98bfb

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lua/opencode/cli/process/unix.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ local M = {}
33
---@param pids number[]
44
---@return table<number, number>
55
local function get_ports(pids)
6-
local pids_to_ports = {}
6+
assert(#pids > 0, "`get_ports` should only be called with a non-empty list of PIDs to filter by")
7+
78
local lsof = vim
89
.system({
910
"lsof",
@@ -22,6 +23,7 @@ local function get_ports(pids)
2223
:wait()
2324
require("opencode.util").check_system_call(lsof, "lsof")
2425

26+
local pids_to_ports = {}
2527
local pid
2628
for line in lsof.stdout:gmatch("[^\n]+") do
2729
local prefix = line:sub(1, 1)
@@ -55,6 +57,10 @@ function M.get()
5557
return tonumber(line)
5658
end, vim.split(pgrep.stdout, "\n", { trimempty = true }))
5759

60+
if #pids == 0 then
61+
return {}
62+
end
63+
5864
local pids_to_ports = get_ports(pids)
5965
---@type opencode.cli.process.Process[]
6066
local processes = {}

0 commit comments

Comments
 (0)