From 2e86d77ae0d72ab5a42440944da73c145b3b2e65 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 22 Nov 2024 09:42:36 +0100 Subject: [PATCH 1/3] fix: Guard against missing release --- src/targets/github.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/targets/github.ts b/src/targets/github.ts index 4d6a7016..47c3d1e3 100644 --- a/src/targets/github.ts +++ b/src/targets/github.ts @@ -127,10 +127,17 @@ export class GitHubTarget extends BaseTarget { }; } - const { data: latestRelease } = await this.github.repos.getLatestRelease({ - owner: this.githubConfig.owner, - repo: this.githubConfig.repo, - }); + let latestRelease: { tag_name: string } | undefined = undefined; + try { + latestRelease = ( + await this.github.repos.getLatestRelease({ + owner: this.githubConfig.owner, + repo: this.githubConfig.repo, + }) + ).data; + } catch { + // no release yet + } const isLatest = isPreview ? false From ac2964be1ecf3e29b6d7ffd18f6e2f15f4a43af0 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 10 Jan 2025 10:36:34 +0100 Subject: [PATCH 2/3] only handle 404 errors --- src/targets/github.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/targets/github.ts b/src/targets/github.ts index 47c3d1e3..48d8d727 100644 --- a/src/targets/github.ts +++ b/src/targets/github.ts @@ -135,8 +135,12 @@ export class GitHubTarget extends BaseTarget { repo: this.githubConfig.repo, }) ).data; - } catch { - // no release yet + } catch (error) { + // if the error is a 404 error, it means that no release exists yet + // all other errors should be rethrown + if (error.status !== 404) { + throw error; + } } const isLatest = isPreview From 69fcc6acea570a6625afdc012d5695f0408cba0a Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Fri, 10 Jan 2025 11:05:48 +0100 Subject: [PATCH 3/3] Update src/targets/github.ts Co-authored-by: Burak Yigit Kaya --- src/targets/github.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targets/github.ts b/src/targets/github.ts index 48d8d727..7dd29c9c 100644 --- a/src/targets/github.ts +++ b/src/targets/github.ts @@ -127,7 +127,7 @@ export class GitHubTarget extends BaseTarget { }; } - let latestRelease: { tag_name: string } | undefined = undefined; + let latestRelease: { tag_name: string } | undefined; try { latestRelease = ( await this.github.repos.getLatestRelease({