mirror of
https://github.com/pesde-pkg/tooling.git
synced 2025-01-09 15:59:09 +00:00
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:
parent
aba182cea5
commit
ed8d5594b9
1 changed files with 9 additions and 7 deletions
|
@ -140,14 +140,16 @@ end
|
|||
|
||||
local function getGithubToken(): Option<string>
|
||||
return Option.from(process.env.GITHUB_TOKEN):orElse(function()
|
||||
local child = process.spawn("gh", { "auth", "token" })
|
||||
if not child.ok then
|
||||
return Option.None
|
||||
end
|
||||
return ResultExt.ok(Result.try(process.spawn, "gh", { "auth", "token" }))
|
||||
:andThen(function(child: process.SpawnResult)
|
||||
if not child.ok then
|
||||
return Option.None
|
||||
end
|
||||
|
||||
-- Remove newlines and other control characters
|
||||
local token = string.gsub(child.stdout, "%s+", "")
|
||||
return Option.Some(token)
|
||||
-- Remove newlines and other control characters
|
||||
local token = string.gsub(child.stdout, "%s+", "")
|
||||
return Option.Some(token)
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue