diff --git a/src/org/scratchOrgCreate.ts b/src/org/scratchOrgCreate.ts index 49c7a4ce5..0753576c7 100644 --- a/src/org/scratchOrgCreate.ts +++ b/src/org/scratchOrgCreate.ts @@ -12,6 +12,7 @@ import { ConfigAggregator } from '../config/configAggregator'; import { OrgConfigProperties } from '../org/orgConfigProperties'; import { SfProject } from '../sfProject'; import { StateAggregator } from '../stateAggregator/stateAggregator'; +import { SfError } from '../sfError'; import { Org } from './org'; import { authorizeScratchOrg, @@ -148,6 +149,15 @@ export const scratchOrgResume = async (jobId: string): Promise => { async function getCapitalizeRecordTypesConfig(): Promise { const configAgg = await ConfigAggregator.create(); const value = configAgg.getInfo('org-capitalize-record-types').value as string | undefined; - - if (value !== undefined) return toBoolean(value); - - // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion - return value as undefined; + return value !== undefined ? toBoolean(value) : undefined; } + +/** wrap an async function, intercept error and set the given exit code */ +const setExitCodeIfError = + (exitCode: number) => + async

(p: Promise

): Promise

=> { + try { + return await p; + } catch (e) { + const sfError = e instanceof SfError ? e : SfError.wrap(e); + sfError.exitCode = exitCode; + throw sfError; + } + }; diff --git a/src/org/scratchOrgSettingsGenerator.ts b/src/org/scratchOrgSettingsGenerator.ts index 229f3369d..2bb9e9ed9 100644 --- a/src/org/scratchOrgSettingsGenerator.ts +++ b/src/org/scratchOrgSettingsGenerator.ts @@ -333,7 +333,6 @@ export default class SettingsGenerator { message: `A scratch org was created with username ${username}, but the settings failed to deploy due to: \n${failures}`, name: 'ProblemDeployingSettings', data: { ...result, username }, - exitCode: 68, }); } } diff --git a/test/unit/org/scratchOrgSettingsGeneratorTest.ts b/test/unit/org/scratchOrgSettingsGeneratorTest.ts index 3696750e3..8e626fab7 100644 --- a/test/unit/org/scratchOrgSettingsGeneratorTest.ts +++ b/test/unit/org/scratchOrgSettingsGeneratorTest.ts @@ -111,7 +111,7 @@ function createStubs() { id: '1', }) ); - sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'mybuffer'); + sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'myBuffer'); getUsernameStub = sandbox.stub(scratchOrg, 'getUsername').returns(adminTestData.username); } @@ -266,7 +266,7 @@ describe('scratchOrgSettingsGenerator', () => { id: '1', }) ); - sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'mybuffer'); + sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'myBuffer'); getUsernameStub = sandbox.stub(scratchOrg, 'getUsername').returns(adminTestData.username); getConnectionStub = fakeConnection(sandbox, scratchOrg, deployId, 'SucceededPartial'); }); @@ -329,7 +329,7 @@ describe('scratchOrgSettingsGenerator', () => { id: '1', }) ); - sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'mybuffer'); + sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'myBuffer'); getUsernameStub = sandbox.stub(scratchOrg, 'getUsername').returns(adminTestData.username); getConnectionStub = fakeConnection(sandbox, scratchOrg, deployId, 'Failed'); }); @@ -392,7 +392,7 @@ describe('scratchOrgSettingsGenerator', () => { id: '1', }) ); - sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'mybuffer'); + sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'myBuffer'); getUsernameStub = sandbox.stub(scratchOrg, 'getUsername').returns(adminTestData.username); getConnectionStub = fakeConnection(sandbox, scratchOrg, deployId, ['InProgress', 'Succeeded']); }); @@ -401,7 +401,7 @@ describe('scratchOrgSettingsGenerator', () => { sandbox.restore(); }); - it('tries to deploy the settings to the org pools untill succeded', async () => { + it('tries to deploy the settings to the org pools until succeeded', async () => { const scratchDef = { ...TEMPLATE_SCRATCH_ORG_INFO, settings: { @@ -497,7 +497,7 @@ describe('scratchOrgSettingsGenerator', () => { id: '1', }) ); - sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'mybuffer'); + sandbox.stub(ZipWriter.prototype, 'buffer').get(() => 'myBuffer'); getUsernameStub = sandbox.stub(scratchOrg, 'getUsername').returns(adminTestData.username); getConnectionStub = fakeConnection(sandbox, scratchOrg, deployId, 'InProgress'); }); @@ -507,7 +507,7 @@ describe('scratchOrgSettingsGenerator', () => { sandbox.restore(); }); - it('tries to deploy the settings to the org pools untill timeouts', async () => { + it('tries to deploy the settings to the org pools until timeouts', async () => { const timeout = 10 * 60 * 1000; // 10 minutes const frequency = 1000; const settings = new SettingsGenerator();