Skip to content

Commit f1413d9

Browse files
Danilo Verde RibeiroDanilo Verde Ribeiro
authored andcommitted
fix(base_url): race condition
1 parent deb6de7 commit f1413d9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

lua/opencode/api_client.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ function OpencodeApiClient:_call(endpoint, method, body, query)
2525
local state = require('opencode.state')
2626
self.base_url = state.opencode_server_job.url:gsub('/$', '')
2727
end
28+
if not self.base_url then
29+
error("OpenCode server URL is not available. Ensure the server is running.")
30+
end
2831
local url = self.base_url .. endpoint
2932

3033
if query then
@@ -356,6 +359,14 @@ end
356359
--- @param on_event fun(event: table) Event callback
357360
--- @return Job The streaming job handle
358361
function OpencodeApiClient:subscribe_to_events(directory, on_event)
362+
if not self.base_url then
363+
local state = require('opencode.state')
364+
self.base_url = state.opencode_server_job.url:gsub('/$', '')
365+
end
366+
if not self.base_url then
367+
error("API client base_url is nil. Call OpencodeApiClient.new() after server startup.")
368+
return nil
369+
end
359370
local url = self.base_url .. '/event'
360371
if directory then
361372
url = url .. '?directory=' .. directory

0 commit comments

Comments
 (0)