fix(lib): unhandled error when no gh CLI present

We did not correctly handle the case if the `gh` CLI was not present,
since `process.spawn` errors. We now wrap it in a `Result.try` and
handle that as required.
This commit is contained in:
Erica Marigold 2024-12-25 15:56:39 +00:00
parent aba182cea5
commit ed8d5594b9
Signed by: DevComp
GPG key ID: 429EF1C337871656

View file

@ -140,7 +140,8 @@ end
local function getGithubToken(): Option<string> local function getGithubToken(): Option<string>
return Option.from(process.env.GITHUB_TOKEN):orElse(function() return Option.from(process.env.GITHUB_TOKEN):orElse(function()
local child = process.spawn("gh", { "auth", "token" }) return ResultExt.ok(Result.try(process.spawn, "gh", { "auth", "token" }))
:andThen(function(child: process.SpawnResult)
if not child.ok then if not child.ok then
return Option.None return Option.None
end end
@ -149,6 +150,7 @@ local function getGithubToken(): Option<string>
local token = string.gsub(child.stdout, "%s+", "") local token = string.gsub(child.stdout, "%s+", "")
return Option.Some(token) return Option.Some(token)
end) end)
end)
end end
_G.interactive = false _G.interactive = false