From f51e6288f2422f0cc6c135aea4b0f92634fc9af9 Mon Sep 17 00:00:00 2001 From: madmaxieee <76544194+madmaxieee@users.noreply.github.com> Date: Sat, 7 Mar 2026 23:27:29 +0800 Subject: [PATCH] fix(server): handle processes without ports Mark the port field as optional in the process definition and update the server logic to reject the promise with a clear error message if a port is not provided. --- lua/opencode/cli/process/init.lua | 2 +- lua/opencode/cli/server.lua | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/opencode/cli/process/init.lua b/lua/opencode/cli/process/init.lua index 2743364..464e689 100644 --- a/lua/opencode/cli/process/init.lua +++ b/lua/opencode/cli/process/init.lua @@ -4,7 +4,7 @@ local M = {} ---Retrieval is platform-dependent. ---@class opencode.cli.process.Process ---@field pid number ----@field port number +---@field port number? ---@return opencode.cli.process.Process[] function M.get() diff --git a/lua/opencode/cli/server.lua b/lua/opencode/cli/server.lua index aba7490..c6cc5a3 100644 --- a/lua/opencode/cli/server.lua +++ b/lua/opencode/cli/server.lua @@ -25,10 +25,13 @@ local M = {} ---Verify that an `opencode` process is responding on the given port, ---and fetch some details about it. ----@param port number +---@param port number? ---@return Promise local function get_server(port) local Promise = require("opencode.promise") + if not port then + return Promise.reject("This process is not listening on any port.") + end return Promise .new(function(resolve, reject) require("opencode.cli.client").get_path(port, function(path)