From ada9fd6db42aa6db0db52b8a81aa7f70b064e914 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 22 Nov 2022 06:04:10 -0800 Subject: [PATCH] fix(dart): throw MissingRequiredFileError if pubspec.yaml is missing (#1756) fix(helm): throw MissingRequiredFileError if Chart.yaml is missing --- src/strategies/dart.ts | 20 ++++++++++++++++---- src/strategies/helm.ts | 18 +++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/strategies/dart.ts b/src/strategies/dart.ts index 1401252e4..f21123e6b 100644 --- a/src/strategies/dart.ts +++ b/src/strategies/dart.ts @@ -21,6 +21,7 @@ import {PubspecYaml} from '../updaters/dart/pubspec-yaml'; import {BaseStrategy, BuildUpdatesOptions} from './base'; import {GitHubFileContents} from '@google-automations/git-file-utils'; import {Update} from '../update'; +import {FileNotFoundError, MissingRequiredFileError} from '../errors'; export class Dart extends BaseStrategy { private pubspecYmlContents?: GitHubFileContents; @@ -64,10 +65,21 @@ export class Dart extends BaseStrategy { private async getPubspecYmlContents(): Promise { if (!this.pubspecYmlContents) { - this.pubspecYmlContents = await this.github.getFileContentsOnBranch( - this.addPath('pubspec.yaml'), - this.targetBranch - ); + try { + this.pubspecYmlContents = await this.github.getFileContentsOnBranch( + this.addPath('pubspec.yaml'), + this.targetBranch + ); + } catch (e) { + if (e instanceof FileNotFoundError) { + throw new MissingRequiredFileError( + this.addPath('pubspec.yaml'), + Dart.name, + `${this.repository.owner}/${this.repository.repo}` + ); + } + throw e; + } } return this.pubspecYmlContents; } diff --git a/src/strategies/helm.ts b/src/strategies/helm.ts index 82ff06406..fbc847566 100644 --- a/src/strategies/helm.ts +++ b/src/strategies/helm.ts @@ -21,6 +21,7 @@ import * as yaml from 'js-yaml'; import {ChartYaml} from '../updaters/helm/chart-yaml'; import {BaseStrategy, BuildUpdatesOptions} from './base'; import {Update} from '../update'; +import {FileNotFoundError, MissingRequiredFileError} from '../errors'; export class Helm extends BaseStrategy { private chartYmlContents?: GitHubFileContents; @@ -63,9 +64,20 @@ export class Helm extends BaseStrategy { private async getChartYmlContents(): Promise { if (!this.chartYmlContents) { - this.chartYmlContents = await this.github.getFileContents( - this.addPath('Chart.yaml') - ); + try { + this.chartYmlContents = await this.github.getFileContents( + this.addPath('Chart.yaml') + ); + } catch (e) { + if (e instanceof FileNotFoundError) { + throw new MissingRequiredFileError( + this.addPath('Chart.yaml'), + Helm.name, + `${this.repository.owner}/${this.repository.repo}` + ); + } + throw e; + } } return this.chartYmlContents; }