From c2d6c8054db8de6fe33847b9869307cadf22b54f Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Mon, 9 Aug 2021 14:38:33 +0200 Subject: [PATCH] Publish should not be blocked on inability to list Signed-off-by: Eric Peterson --- .../techdocs-common/src/stages/publish/awsS3.ts | 17 ++++++++++++----- .../src/stages/publish/azureBlobStorage.ts | 12 ++++++------ .../src/stages/publish/googleStorage.ts | 13 ++++++++++--- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/techdocs-common/src/stages/publish/awsS3.ts b/packages/techdocs-common/src/stages/publish/awsS3.ts index 3ba5ffe4e3..02d4f7226f 100644 --- a/packages/techdocs-common/src/stages/publish/awsS3.ts +++ b/packages/techdocs-common/src/stages/publish/awsS3.ts @@ -178,11 +178,18 @@ export class AwsS3Publish implements PublisherBase { * Directory structure used in the bucket is - entityNamespace/entityKind/entityName/index.html */ async publish({ entity, directory }: PublishRequest): Promise { - // First, retrieve a list of all individual files in currently existing - const remoteFolder = getCloudPathForLocalPath(entity); - const existingFiles = await this.getAllObjectsFromBucket({ - prefix: remoteFolder, - }); + // First, try to retrieve a list of all individual files currently existing + let existingFiles: string[] = []; + try { + const remoteFolder = getCloudPathForLocalPath(entity); + existingFiles = await this.getAllObjectsFromBucket({ + prefix: remoteFolder, + }); + } catch (e) { + this.logger.error( + `Unable to list files for Entity ${entity.metadata.name}: ${e.message}`, + ); + } // Then, merge new files into the same folder let absoluteFilesToUpload; diff --git a/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts b/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts index 4fbe071d1c..f1c62f0819 100644 --- a/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts +++ b/packages/techdocs-common/src/stages/publish/azureBlobStorage.ts @@ -137,18 +137,18 @@ export class AzureBlobStoragePublish implements PublisherBase { * Directory structure used in the container is - entityNamespace/entityKind/entityName/index.html */ async publish({ entity, directory }: PublishRequest): Promise { - // First, retrieve a list of all individual files in currently existing + // First, try to retrieve a list of all individual files currently existing const remoteFolder = getCloudPathForLocalPath(entity); - let existingFiles: string[]; + let existingFiles: string[] = []; try { existingFiles = await this.getAllBlobsFromContainer({ prefix: remoteFolder, maxPageSize: BATCH_CONCURRENCY, }); } catch (e) { - const errorMessage = `Unable to list file(s) to Azure. ${e}`; - this.logger.error(errorMessage); - throw new Error(errorMessage); + this.logger.error( + `Unable to list files for Entity ${entity.metadata.name}: ${e.message}`, + ); } // Then, merge new files into the same folder @@ -395,7 +395,7 @@ export class AzureBlobStoragePublish implements PublisherBase { let response = (await iterator.next()).value; do { - for (const blob of response.segment.blobItems) { + for (const blob of response?.segment?.blobItems ?? []) { blobs.push(blob.name); } iterator = container diff --git a/packages/techdocs-common/src/stages/publish/googleStorage.ts b/packages/techdocs-common/src/stages/publish/googleStorage.ts index 24f84f0136..9d8566f0b3 100644 --- a/packages/techdocs-common/src/stages/publish/googleStorage.ts +++ b/packages/techdocs-common/src/stages/publish/googleStorage.ts @@ -117,9 +117,16 @@ export class GoogleGCSPublish implements PublisherBase { async publish({ entity, directory }: PublishRequest): Promise { const bucket = this.storageClient.bucket(this.bucketName); - // First, retrieve a list of all individual files in currently existing - const remoteFolder = getCloudPathForLocalPath(entity); - const existingFiles = await this.getFilesForFolder(remoteFolder); + // First, try to retrieve a list of all individual files currently existing + let existingFiles: string[] = []; + try { + const remoteFolder = getCloudPathForLocalPath(entity); + existingFiles = await this.getFilesForFolder(remoteFolder); + } catch (e) { + this.logger.error( + `Unable to list files for Entity ${entity.metadata.name}: ${e.message}`, + ); + } // Then, merge new files into the same folder let absoluteFilesToUpload;