Skip to content

Commit

Permalink
fix: catch no updates CFN error and fix CFN poller hang (#7548)
Browse files Browse the repository at this point in the history
* fix: catch no updates CFN error and fix CFN poller hang

* chore: remove other mentions of persistContext
  • Loading branch information
edwardfoyle authored Jun 18, 2021
1 parent a23ab9b commit 312eec3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
1 change: 0 additions & 1 deletion packages/amplify-cli/src/__tests__/test-aborting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ describe('test SIGINT with execute', () => {
mockContext.amplify = jest.genMockFromModule('../domain/amplify-toolkit');
jest.setMock('../context-manager', {
constructContext: jest.fn().mockReturnValue(mockContext),
persistContext: jest.fn(),
attachUsageData: jest.fn(),
});

Expand Down
4 changes: 0 additions & 4 deletions packages/amplify-cli/src/context-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,3 @@ const getProjectSettings = (): ProjectSettings => {

return projectSettings;
};
export function persistContext(context: Context): void {
// write to the backend and current backend
// and get the frontend plugin to write to the config files.
}
6 changes: 1 addition & 5 deletions packages/amplify-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as fs from 'fs-extra';
import * as path from 'path';
import { logInput } from './conditional-local-logging-init';
import { print } from './context-extensions';
import { attachUsageData, constructContext, persistContext } from './context-manager';
import { attachUsageData, constructContext } from './context-manager';
import { displayBannerMessages } from './display-banner-messages';
import { constants } from './domain/constants';
import { Context } from './domain/context';
Expand Down Expand Up @@ -156,8 +156,6 @@ export async function run() {
context.usageData.emitSuccess();
}

persistContext(context);

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

persistContext(context);

return exitCode;
} catch (e) {
// ToDo: add logging to the core, and log execution errors using the unified core logging.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ class CloudFormation {

const cfnCompleteStatus = 'stackUpdateComplete';
if (updateErr) {
console.error('Error updating cloudformation stack');
reject(updateErr);
if (self.pollForEvents) {
clearInterval(self.pollForEvents);
}
return reject(updateErr);
}
cfnModel.waitFor(cfnCompleteStatus, cfnStackCheckParams, completeErr => {
if (self.pollForEvents) {
clearInterval(self.pollForEvents);
}
if (completeErr) {
console.error('Error updating cloudformation stack');
this.collectStackErrors(cfnParentStackParams.StackName).then(() => reject(completeErr));
} else {
return self.updateamplifyMetaFileWithStackOutputs(stackName).then(() => resolve());
Expand Down Expand Up @@ -463,7 +464,7 @@ class CloudFormation {
cfnModel.deleteStack(cfnStackParams, deleteErr => {
if (deleteErr) {
console.log(`Error deleting stack ${stackName}`);
reject(deleteErr);
return reject(deleteErr);
}
cfnModel.waitFor(cfnDeleteStatus, cfnStackParams, completeErr => {
if (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,17 @@ export async function run(context: $TSContext, resourceDefinition: $TSObject) {

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

await updateCloudFormationNestedStack(context, nestedStack, resourcesToBeCreated, resourcesToBeUpdated);
try {
await updateCloudFormationNestedStack(context, nestedStack, resourcesToBeCreated, resourcesToBeUpdated);
} catch (err) {
if (err?.name === 'ValidationError' && err?.message === 'No updates are to be performed.') {
return;
} else {
throw err;
}
} finally {
spinner.stop();
}
}
}

Expand Down

0 comments on commit 312eec3

Please sign in to comment.