From 7747f74b6a0606d390cca15bfb574c1eaceec274 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 1 Mar 2023 12:35:51 -0700 Subject: [PATCH] fix: warn if plugin doesnt have snapshot --- src/commands/cli/artifacts/compare.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/commands/cli/artifacts/compare.ts b/src/commands/cli/artifacts/compare.ts index 42295212..692f2839 100644 --- a/src/commands/cli/artifacts/compare.ts +++ b/src/commands/cli/artifacts/compare.ts @@ -575,16 +575,22 @@ export default class ArtifactsTest extends SfCommand { private async getSnapshot(owner: string, repo: string, ref: string | null): Promise { if (!ref) return []; - const response = await this.octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { - owner, - repo, - path: 'command-snapshot.json', - accept: 'application/vnd.github.json', - ref, - }); - // @ts-expect-error octokit doesn't have a type for this - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - return JSON.parse(Buffer.from(response.data.content ?? '', 'base64').toString()) as CommandSnapshot[]; + try { + const response = await this.octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { + owner, + repo, + path: 'command-snapshot.json', + accept: 'application/vnd.github.json', + ref, + }); + // @ts-expect-error octokit doesn't have a type for this + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument + return JSON.parse(Buffer.from(response.data.content ?? '', 'base64').toString()) as CommandSnapshot[]; + } catch { + this.warn(`No command-snapshot.json found for ${owner}/${repo}@${ref}`); + return []; + } + } private async getTags(owner: string, repo: string): Promise {