From d812e7e053da8cb8c839cee9b2c7591ac6207c7e Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 9 Dec 2021 11:31:04 -0600 Subject: [PATCH 1/4] fix: network error tolerance --- src/client/metadataTransfer.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/client/metadataTransfer.ts b/src/client/metadataTransfer.ts index 78fb58cfcb..762dd3add5 100644 --- a/src/client/metadataTransfer.ts +++ b/src/client/metadataTransfer.ts @@ -14,7 +14,6 @@ import { MetadataConverter, SfdxFileFormat } from '../convert'; import { MetadataTransferError } from '../errors'; import { ComponentSet } from '../collections'; import { AsyncResult, MetadataRequestStatus, MetadataTransferResult, RequestStatus } from './types'; - export interface MetadataTransferOptions { usernameOrConnection: string | Connection; components?: ComponentSet; @@ -191,10 +190,21 @@ export abstract class MetadataTransfer Date: Thu, 9 Dec 2021 13:50:22 -0600 Subject: [PATCH 2/4] test: ut for network errors --- test/client/metadataTransfer.test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/client/metadataTransfer.test.ts b/test/client/metadataTransfer.test.ts index a3430d4e83..90f4de36c5 100644 --- a/test/client/metadataTransfer.test.ts +++ b/test/client/metadataTransfer.test.ts @@ -215,7 +215,6 @@ describe('MetadataTransfer', () => { const originalError = new Error('whoops'); const expectedError = new MetadataTransferError('md_request_fail', originalError.message); checkStatus.throws(originalError); - let error: Error; operation.onError((e) => (error = e)); await operation.pollStatus(); @@ -224,6 +223,18 @@ describe('MetadataTransfer', () => { expect(error.message).to.deep.equal(expectedError.message); }); + it('should tolerate network errors', async () => { + const { checkStatus } = operation.lifecycle; + const networkError1 = new Error('something something ETIMEDOUT something'); + const networkError2 = new Error('something something ENOTFOUND something'); + checkStatus.onFirstCall().throws(networkError1); + checkStatus.onSecondCall().throws(networkError2); + checkStatus.onThirdCall().resolves({ done: true }); + + await operation.pollStatus(); + expect(checkStatus.callCount).to.equal(3); + }); + it('should throw wrapped error if there are no error listeners', async () => { const { checkStatus } = operation.lifecycle; const originalError = new Error('whoops'); From c74a16b4fcf86f83dcebe663829c21f9baa95fec Mon Sep 17 00:00:00 2001 From: mshanemc Date: Thu, 9 Dec 2021 15:01:48 -0600 Subject: [PATCH 3/4] feat: more network error types --- src/client/metadataTransfer.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/metadataTransfer.ts b/src/client/metadataTransfer.ts index 762dd3add5..1fbe528fc0 100644 --- a/src/client/metadataTransfer.ts +++ b/src/client/metadataTransfer.ts @@ -199,8 +199,14 @@ export abstract class MetadataTransfer Date: Thu, 9 Dec 2021 15:10:36 -0600 Subject: [PATCH 4/4] refactor: array.some --- src/client/metadataTransfer.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client/metadataTransfer.ts b/src/client/metadataTransfer.ts index 1fbe528fc0..891e5a6cbd 100644 --- a/src/client/metadataTransfer.ts +++ b/src/client/metadataTransfer.ts @@ -200,11 +200,9 @@ export abstract class MetadataTransfer + (e as Error).message.includes(retryableNetworkError) + ) ) { this.logger.debug('Network error on the request', e); await Lifecycle.getInstance().emitWarning('Network error occurred. Continuing to poll.');