Skip to content

Commit 312eec3

Browse files
authored
fix: catch no updates CFN error and fix CFN poller hang (#7548)
* fix: catch no updates CFN error and fix CFN poller hang * chore: remove other mentions of persistContext
1 parent a23ab9b commit 312eec3

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

packages/amplify-cli/src/__tests__/test-aborting.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ describe('test SIGINT with execute', () => {
7474
mockContext.amplify = jest.genMockFromModule('../domain/amplify-toolkit');
7575
jest.setMock('../context-manager', {
7676
constructContext: jest.fn().mockReturnValue(mockContext),
77-
persistContext: jest.fn(),
7877
attachUsageData: jest.fn(),
7978
});
8079

packages/amplify-cli/src/context-manager.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,3 @@ const getProjectSettings = (): ProjectSettings => {
4545

4646
return projectSettings;
4747
};
48-
export function persistContext(context: Context): void {
49-
// write to the backend and current backend
50-
// and get the frontend plugin to write to the config files.
51-
}

packages/amplify-cli/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as fs from 'fs-extra';
1717
import * as path from 'path';
1818
import { logInput } from './conditional-local-logging-init';
1919
import { print } from './context-extensions';
20-
import { attachUsageData, constructContext, persistContext } from './context-manager';
20+
import { attachUsageData, constructContext } from './context-manager';
2121
import { displayBannerMessages } from './display-banner-messages';
2222
import { constants } from './domain/constants';
2323
import { Context } from './domain/context';
@@ -156,8 +156,6 @@ export async function run() {
156156
context.usageData.emitSuccess();
157157
}
158158

159-
persistContext(context);
160-
161159
// no command supplied defaults to help, give update notification at end of execution
162160
if (input.command === 'help') {
163161
// Checks for available update, defaults to a 1 day interval for notification
@@ -290,8 +288,6 @@ export async function execute(input: Input): Promise<number> {
290288
context.usageData.emitSuccess();
291289
}
292290

293-
persistContext(context);
294-
295291
return exitCode;
296292
} catch (e) {
297293
// ToDo: add logging to the core, and log execution errors using the unified core logging.

packages/amplify-provider-awscloudformation/src/aws-utils/aws-cfn.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,16 @@ class CloudFormation {
286286

287287
const cfnCompleteStatus = 'stackUpdateComplete';
288288
if (updateErr) {
289-
console.error('Error updating cloudformation stack');
290-
reject(updateErr);
289+
if (self.pollForEvents) {
290+
clearInterval(self.pollForEvents);
291+
}
292+
return reject(updateErr);
291293
}
292294
cfnModel.waitFor(cfnCompleteStatus, cfnStackCheckParams, completeErr => {
293295
if (self.pollForEvents) {
294296
clearInterval(self.pollForEvents);
295297
}
296298
if (completeErr) {
297-
console.error('Error updating cloudformation stack');
298299
this.collectStackErrors(cfnParentStackParams.StackName).then(() => reject(completeErr));
299300
} else {
300301
return self.updateamplifyMetaFileWithStackOutputs(stackName).then(() => resolve());
@@ -463,7 +464,7 @@ class CloudFormation {
463464
cfnModel.deleteStack(cfnStackParams, deleteErr => {
464465
if (deleteErr) {
465466
console.log(`Error deleting stack ${stackName}`);
466-
reject(deleteErr);
467+
return reject(deleteErr);
467468
}
468469
cfnModel.waitFor(cfnDeleteStatus, cfnStackParams, completeErr => {
469470
if (err) {

packages/amplify-provider-awscloudformation/src/push-resources.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,17 @@ export async function run(context: $TSContext, resourceDefinition: $TSObject) {
263263

264264
const nestedStack = await formNestedStack(context, context.amplify.getProjectDetails());
265265

266-
await updateCloudFormationNestedStack(context, nestedStack, resourcesToBeCreated, resourcesToBeUpdated);
266+
try {
267+
await updateCloudFormationNestedStack(context, nestedStack, resourcesToBeCreated, resourcesToBeUpdated);
268+
} catch (err) {
269+
if (err?.name === 'ValidationError' && err?.message === 'No updates are to be performed.') {
270+
return;
271+
} else {
272+
throw err;
273+
}
274+
} finally {
275+
spinner.stop();
276+
}
267277
}
268278
}
269279

0 commit comments

Comments
 (0)