Skip to content

Commit

Permalink
fix: all floating promises (aws-amplify#12293)
Browse files Browse the repository at this point in the history
* fix: all floating promises

* fix: make arrow functions async that have awaits
  • Loading branch information
Amplifiyer authored and akshbhu committed Apr 17, 2023
1 parent 9221544 commit 5c3cccf
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const console = async (amplifyMeta: $TSMeta, provider: string, service: s
}
const { BucketName: bucket, Region: region } = s3Resource.output;
const url = `https://s3.console.aws.amazon.com/s3/buckets/${bucket}?region=${region}`;
open(url, { wait: false });
await open(url, { wait: false });
} else if (service === AmplifySupportedService.DYNAMODB) {
type Pickchoice = { name: string; value: { tableName: string; region: string } };
const tables: Pickchoice[] = Object.values<any>(amplifyMeta[categoryName])
Expand All @@ -199,6 +199,6 @@ export const console = async (amplifyMeta: $TSMeta, provider: string, service: s
}
const { tableName, region } = await prompter.pick<'one', Pickchoice['value']>('Select DynamoDB table to open on your browser', tables);
const url = `https://${region}.console.aws.amazon.com/dynamodbv2/home?region=${region}#table?name=${tableName}&tab=overview`;
open(url, { wait: false });
await open(url, { wait: false });
}
};
2 changes: 0 additions & 2 deletions packages/amplify-console-hosting/src/hosting/cicd/enable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO disable lint until file is converted to TS
/* eslint-disable */
const { open } = require('amplify-cli-core');
const fs = require('fs-extra');
const utils = require('../../utils/amplify-context-utils');
Expand Down
5 changes: 2 additions & 3 deletions packages/amplify-console-hosting/src/hosting/cicd/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable */
const enableMod = require('./enable');
const publshMod = require('./publish');
const publishMod = require('./publish');
const initMod = require('./initEnv');
const serveMod = require('./serve');
const configureMod = require('./configure');
Expand All @@ -10,7 +9,7 @@ async function enable(context) {
}

async function publish(context) {
await publshMod.publish(context);
await publishMod.publish(context);
}

async function initEnv(context) {
Expand Down
3 changes: 1 addition & 2 deletions packages/amplify-console-hosting/src/hosting/cicd/initEnv.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
const constants = require('../../constants/plugin-constants');
const configUtils = require('../../utils/config-utils');
const utils = require('../../utils/amplify-context-utils');
Expand All @@ -16,7 +15,7 @@ async function initEnv(context) {
context.amplify.updateamplifyMetaAfterResourceUpdate(category, resourceName, type, constants.TYPE_CICD);
const metaContent = utils.getMetaInfo(context);
const { lastPushTimeStamp } = metaContent[category][resourceName];
configUtils.initCurrBackendMeta(context, category, resourceName, type, lastPushTimeStamp);
await configUtils.initCurrBackendMeta(context, category, resourceName, type, lastPushTimeStamp);
}

module.exports = {
Expand Down
10 changes: 4 additions & 6 deletions packages/amplify-console-hosting/src/hosting/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// disabling eslint until this file is migrated to TS
/* eslint-disable */
/* eslint-disable spellcheck/spell-checker */
const constants = require('../constants/plugin-constants');
const pathManager = require('../utils/path-manager');
const fs = require('fs-extra');
Expand All @@ -8,7 +7,7 @@ const configUtils = require('../utils/config-utils');
const questions = require('../modules/questions/question-generator');
const ValidationError = require('../error/validation-error').default;
const clientFactory = require('../utils/client-factory');
const tableUtis = require('../utils/table-utils');
const tableUtils = require('../utils/table-utils');
const { ensureEnvParamManager } = require('@aws-amplify/amplify-environment-parameters');
const { spinner } = require('amplify-cli-core');

Expand Down Expand Up @@ -63,7 +62,7 @@ async function initEnv(context) {
// hosting is deleted. But current env config is not cleaned
const { type } = consoleConfig;
// clean team provider info
await configUtils.deleteHostingEnvParams(context);
await configUtils.deleteHostingEnvParams();
// clean #current-backend-env for CICD.
if (type === constants.TYPE_CICD) {
await configUtils.deleteConsoleConfigFromCurrMeta(context);
Expand Down Expand Up @@ -133,7 +132,7 @@ async function status(context, mute) {
}

const appId = utils.getAppIdForCurrEnv(context);
await tableUtis.generateTableContentForApp(context, appId);
await tableUtils.generateTableContentForApp(context, appId);
}

function loadDeployType(context) {
Expand Down Expand Up @@ -184,4 +183,3 @@ module.exports = {
configure,
status,
};
/* eslint-enable */
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
const path = require('path');
const constants = require('../../constants/plugin-constants');
const configUtils = require('../../utils/config-utils');
Expand Down
9 changes: 4 additions & 5 deletions packages/amplify-console-hosting/src/hosting/manual/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* eslint-disable */
const enableMod = require('./enable');
const publshMod = require('./publish');
const publishMod = require('./publish');
const initMod = require('./initEnv');
const serveMod = require('./serve');
const configureMod = require('./configure');

function enable(context) {
enableMod.enable(context);
async function enable(context) {
await enableMod.enable(context);
}

async function publish(context, doSkipBuild, doSkipPush) {
await publshMod.publish(context, doSkipBuild, doSkipPush);
await publishMod.publish(context, doSkipBuild, doSkipPush);
}

async function initEnv(context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable */
const constants = require('../../constants/plugin-constants');
const configUtils = require('../../utils/config-utils');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ async function publish(context, doSkipBuild, doSkipPush) {
const appId = utils.getAppIdForCurrEnv(context);
const env = utils.getCurrEnv(context);
spinner.start(ZIPPING_MESSAGE);
artifactsPath = await zipArtifacts(context).catch((err) => {
try {
artifactsPath = await zipArtifacts(context);
} catch (err) {
spinner.fail(ZIPPING_FAILURE_MESSAGE);
throw err;
});
}
spinner.succeed(ZIPPING_SUCCESS_MESSAGE);
await amplifyUtils.publishFileToAmplify(appId, env, artifactsPath, amplifyClient);
context.print.info(amplifyUtils.getDefaultDomainForBranch(appId, env));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// disabling eslint until this file is migrated to TS
/* eslint-disable */
const constants = require('../constants/plugin-constants');
const pathManager = require('../utils/path-manager');
const fs = require('fs-extra');
Expand Down Expand Up @@ -48,4 +46,3 @@ module.exports = {
getRegionForCurrEnv,
getMetaInfo,
};
/* eslint-enable */
7 changes: 3 additions & 4 deletions packages/amplify-console-hosting/src/utils/config-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// disabling eslint until this file is migrated to TS
/* eslint-disable */
/* eslint-disable spellcheck/spell-checker */
const fs = require('fs-extra');
const path = require('path');
const { pathManager, PathConstants, stateManager } = require('amplify-cli-core');
Expand Down Expand Up @@ -110,8 +109,7 @@ async function deleteConsoleConfigFromCurrMeta(context) {
await storeCurrentCloudBackend(context);
}

async function deleteHostingEnvParams(context) {
const categories = constants.CATEGORIES;
async function deleteHostingEnvParams() {
const category = constants.CATEGORY;
const resourceName = constants.CONSOLE_RESOURCE_NAME;

Expand Down Expand Up @@ -169,6 +167,7 @@ async function storeCurrentCloudBackend(context) {
}
}

// eslint-disable-next-line consistent-return
async function uploadFile(s3, filePath, key) {
if (fs.existsSync(filePath)) {
const s3Params = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class CloudFormation {
// add root stack to see the new stacks
this.readStackEvents(stackName);
// wait for the poll queue to drain
return new Promise((resolve) => {
return new Promise((resolve, reject) => {
this.pollQueue.once('empty', () => {
const failedStacks = this.stackEvents.filter((ev) => CNF_ERROR_STATUS.includes(ev.ResourceStatus));

Expand All @@ -130,7 +130,7 @@ class CloudFormation {
});
resolve(collectStackErrorMessages(this.filterFailedStackEvents(failedStacks)));
} catch (e) {
Promise.reject(e);
reject(e);
} finally {
if (this.pollForEvents) {
clearTimeout(this.pollForEvents);
Expand Down Expand Up @@ -397,20 +397,21 @@ class CloudFormation {
}
return reject(updateErr);
}
cfnModel.waitFor(cfnCompleteStatus, cfnStackCheckParams, (completeErr) => {
cfnModel.waitFor(cfnCompleteStatus, cfnStackCheckParams, async (completeErr) => {
if (self.pollForEvents) {
clearTimeout(self.pollForEvents);
}
this.progressBar?.stop();

if (completeErr) {
this.collectStackErrors(cfnParentStackParams.StackName).then((errorDetails) => {
await this.collectStackErrors(cfnParentStackParams.StackName).then((errorDetails) => {
completeErr.details = errorDetails;
reject(completeErr);
});
} else {
self.context.usageData.calculatePushNormalizationFactor(this.stackEvents, stackId);
return self.updateamplifyMetaFileWithStackOutputs(stackName).then(() => resolve());
await self.updateamplifyMetaFileWithStackOutputs(stackName);
return resolve();
}
});
});
Expand Down Expand Up @@ -563,12 +564,12 @@ class CloudFormation {
const log = logger('listExports.cfn.listExports', [{ NextToken: nextToken }]);
return new Promise((resolve, reject) => {
log();
this.cfn.listExports(nextToken ? { NextToken: nextToken } : {}, (err, data) => {
this.cfn.listExports(nextToken ? { NextToken: nextToken } : {}, async (err, data) => {
if (err) {
log(err);
reject(err);
} else if (data.NextToken) {
this.listExports(data.NextToken).then((innerExports) => resolve([...data.Exports, ...innerExports]));
await this.listExports(data.NextToken).then((innerExports) => resolve([...data.Exports, ...innerExports]));
} else {
resolve(data.Exports);
}
Expand Down Expand Up @@ -644,10 +645,10 @@ class CloudFormation {
console.log(`Error deleting stack ${stackName}`);
return reject(deleteErr);
}
cfnModel.waitFor(cfnDeleteStatus, cfnStackParams, (completeErr) => {
cfnModel.waitFor(cfnDeleteStatus, cfnStackParams, async (completeErr) => {
if (err) {
console.log(`Error deleting stack ${stackName}`);
this.collectStackErrors(stackName).then((errorDetails) => {
await this.collectStackErrors(stackName).then((errorDetails) => {
completeErr.details = errorDetails;
reject(completeErr);
});
Expand Down

0 comments on commit 5c3cccf

Please sign in to comment.