From ed8d5594b9af1a87d264a1089efc274d42ba2561 Mon Sep 17 00:00:00 2001 From: Erica Marigold Date: Wed, 25 Dec 2024 15:56:39 +0000 Subject: [PATCH] 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. --- toolchainlib/src/init.luau | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/toolchainlib/src/init.luau b/toolchainlib/src/init.luau index ec08d3a..681e99f 100644 --- a/toolchainlib/src/init.luau +++ b/toolchainlib/src/init.luau @@ -140,14 +140,16 @@ end local function getGithubToken(): Option 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