Skip to content

Commit

Permalink
fix: added exit code on remove (#5427)
Browse files Browse the repository at this point in the history
* fix: added exit code on remove

* fix: added exit code

* fix: exit on next tick

* test: fixed abort test

* test: fixed delete.test.ts
  • Loading branch information
ammarkarachi committed Sep 29, 2020
1 parent 3076b05 commit 33132f7
Show file tree
Hide file tree
Showing 52 changed files with 195 additions and 184 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NotImplementedError } from 'amplify-cli-core';
import { NotImplementedError, exitOnNextTick } from 'amplify-cli-core';
function addResource(context, category, service) {
const serviceMetadata = context.amplify.readJsonFile(`${__dirname}/../supported-services.json`)[service];
const { defaultValuesFilename, serviceWalkthroughFilename } = serviceMetadata;
Expand All @@ -19,7 +19,7 @@ function updateResource(context, category, service) {
const message = 'Update functionality not available for this service';
context.print.error(message);
context.usageData.emitError(new NotImplementedError(message));
process.exit(0);
exitOnNextTick(0);
}

return updateWalkthrough(context, defaultValuesFilename, serviceMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');
// FIXME: may be removed from here, since addResource can pass category to addWalkthrough
const category = 'analytics';
const service = 'Kinesis';
const { ResourceAlreadyExistsError, ResourceDoesNotExistError } = require('amplify-cli-core');
const { ResourceAlreadyExistsError, ResourceDoesNotExistError, exitOnNextTick } = require('amplify-cli-core');

async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const resourceName = resourceAlreadyExists(context);
Expand All @@ -12,7 +12,7 @@ async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const errMessage = 'Kinesis resource have already been added to your project.';
context.print.warning(errMessage);
context.usageData.emitError(new ResourceAlreadyExistsError(errMessage));
process.exit(0);
exitOnNextTick(0);
}
return configure(context, defaultValuesFilename, serviceMetadata);
}
Expand Down Expand Up @@ -136,7 +136,7 @@ async function updateWalkthrough(context, defaultValuesFilename, serviceMetadata
const errMessage = 'No Kinesis streams resource to update. Please use "amplify add analytics" command to create a new Kinesis stream';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
return;
} else if (kinesisResources.length === 1) {
[targetResourceName] = kinesisResources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const category = 'analytics';
const parametersFileName = 'parameters.json';
const serviceName = 'Pinpoint';
const templateFileName = 'pinpoint-cloudformation-template.json';
import { ResourceAlreadyExistsError } from 'amplify-cli-core';
import { ResourceAlreadyExistsError, exitOnNextTick } from 'amplify-cli-core';

async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const resourceName = resourceAlreadyExists(context);
Expand All @@ -17,7 +17,7 @@ async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const errMessage = 'Pinpoint analytics have already been added to your project.';
context.print.warning(errMessage);
context.usageData.emitError(new ResourceAlreadyExistsError(errMessage));
process.exit(0);
exitOnNextTick(0);
} else {
return configure(context, defaultValuesFilename, serviceMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const { RelationalDBSchemaTransformer } = require('graphql-relational-schema-transformer');
const { RelationalDBTemplateGenerator, AuroraServerlessMySQLDatabaseReader } = require('graphql-relational-schema-transformer');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const { ResourceDoesNotExistError } = require('amplify-cli-core');
const { ResourceDoesNotExistError, exitOnNextTick } = require('amplify-cli-core');

const subcommand = 'add-graphql-datasource';
const categories = 'categories';
Expand Down Expand Up @@ -191,7 +191,7 @@ function datasourceSelectionPrompt(context, supportedDatasources) {
const errMessage = `No datasources defined by configured providers for category: ${category}`;
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(1);
exitOnNextTick(1);
}

if (options.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { legacyAddResource } from './legacy-add-resource';
import { legacyUpdateResource } from './legacy-update-resource';
import { UpdateApiRequest } from 'amplify-headless-interface';
import { editSchemaFlow } from './utils/edit-schema-flow';
import { NotImplementedError } from 'amplify-cli-core';
import { NotImplementedError, exitOnNextTick } from 'amplify-cli-core';

export async function console(context, service) {
const { serviceWalkthroughFilename } = await serviceMetadataFor(service);
Expand All @@ -16,7 +16,7 @@ export async function console(context, service) {
const errMessage = 'Opening console functionality not available for this option';
context.print.error(errMessage);
context.usageData.emitError(new NotImplementedError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

return openConsole(context);
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function updateResource(context, category, service) {
const errMessage = 'Update functionality not available for this option';
context.print.error(errMessage);
context.usageData.emitError(new NotImplementedError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

const updateWalkthroughPromise: Promise<UpdateApiRequest> = updateWalkthrough(context, defaultValuesFilename, serviceMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import uuid from 'uuid';
import { rootAssetDir } from '../aws-constants';
import { checkForPathOverlap, validatePathName, formatCFNPathParamsForExpressJs } from '../utils/rest-api-path-utils';
import { ServiceName as FunctionServiceName } from 'amplify-category-function';
import { ResourceDoesNotExistError } from 'amplify-cli-core';
import { ResourceDoesNotExistError, exitOnNextTick } from 'amplify-cli-core';

const category = 'api';
const serviceName = 'API Gateway';
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function updateWalkthrough(context, defaultValuesFilename) {
const errMessage = 'No REST API resource to update. Please use "amplify add api" command to create a new REST API';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
return;
}

Expand Down Expand Up @@ -74,7 +74,7 @@ export async function updateWalkthrough(context, defaultValuesFilename) {
const errMessage = `The Admin Queries API is maintained through the Auth category and should be updated using 'amplify update auth' command`;
context.print.warning(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

const projectBackendDirPath = context.amplify.pathManager.getBackendDirPath();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const inquirer = require('inquirer');
const ora = require('ora');
const { DataApiParams } = require('graphql-relational-schema-transformer');
const { ResourceDoesNotExistError, ResourceCredentialsNotFoundError } = require('amplify-cli-core');
const { ResourceDoesNotExistError, ResourceCredentialsNotFoundError, exitOnNextTick } = require('amplify-cli-core');

const spinner = ora('');
const category = 'api';
Expand All @@ -16,7 +16,7 @@ async function serviceWalkthrough(context, defaultValuesFilename, datasourceMeta
'You must create an AppSync API in your project before adding a graphql datasource. Please use "amplify api add" to create the API.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

// Loop through to find the AppSync API Resource Name
Expand All @@ -36,7 +36,7 @@ async function serviceWalkthrough(context, defaultValuesFilename, datasourceMeta
'You must create an AppSync API in your project before adding a graphql datasource. Please use "amplify api add" to create the API.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

const { inputs, availableRegions } = datasourceMetadata;
Expand Down Expand Up @@ -98,7 +98,7 @@ async function selectCluster(context, inputs, AWS) {
const errMessage = 'No properly configured Aurora Serverless clusters found.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

/**
Expand Down Expand Up @@ -150,7 +150,7 @@ async function getSecretStoreArn(context, inputs, clusterResourceId, AWS) {
const errMessage = 'No RDS access credentials found in the AWS Secrect Manager.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceCredentialsNotFoundError(errMessage));
process.exit(0);
exitOnNextTick(0);
}
}

Expand Down Expand Up @@ -195,7 +195,7 @@ async function selectDatabase(context, inputs, clusterArn, secretArn, AWS) {
const errMessage = 'No properly configured databases found.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { authConfigToAppSyncAuthType } from '../utils/auth-config-to-app-sync-au
import { resolverConfigToConflictResolution } from '../utils/resolver-config-to-conflict-resolution-bi-di-mapper';
import _ from 'lodash';
import { getAppSyncAuthConfig, checkIfAuthExists, authConfigHasApiKey } from '../utils/amplify-meta-utils';
import { ResourceAlreadyExistsError, ResourceDoesNotExistError, UnknownResourceTypeError } from 'amplify-cli-core';
import { ResourceAlreadyExistsError, ResourceDoesNotExistError, UnknownResourceTypeError, exitOnNextTick } from 'amplify-cli-core';

const serviceName = 'AppSync';
const providerName = 'awscloudformation';
Expand Down Expand Up @@ -69,7 +69,7 @@ export const serviceWalkthrough = async (context, defaultValuesFilename, service
'You already have an AppSync API in your project. Use the "amplify update api" command to update your existing AppSync API.';
context.print.warning(errMessage);
context.usageData.emitError(new ResourceAlreadyExistsError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

const { amplify } = context;
Expand Down Expand Up @@ -180,7 +180,7 @@ export const updateWalkthrough = async (context): Promise<UpdateApiRequest> => {
const errMessage = 'No AppSync resource to update. Use the "amplify add api" command to update your existing AppSync API.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

// Get models
Expand Down Expand Up @@ -499,7 +499,7 @@ async function askAuthQuestions(authType, context, printLeadText = false) {
const errMessage = `Unknown authType: ${authType}`;
context.print.error(errMessage);
context.usageData.emitError(new UnknownResourceTypeError(errMessage));
process.exit(1);
exitOnNextTick(1);
}

async function askUserPoolQuestions(context) {
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-category-auth/src/commands/auth/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error removing the auth resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
layerVersionQuestion,
} from '../utils/layerHelpers';
import { ServiceName } from '../utils/constants';
import { ResourceDoesNotExistError } from 'amplify-cli-core';
import { ResourceDoesNotExistError, exitOnNextTick } from 'amplify-cli-core';

export async function createLayerWalkthrough(context: any, parameters: Partial<LayerParameters> = {}): Promise<Partial<LayerParameters>> {
_.assign(parameters, await inquirer.prompt(layerNameQuestion(context)));
Expand Down Expand Up @@ -55,7 +55,7 @@ export async function updateLayerWalkthrough(
const errMessage = 'No Lambda layer resource to update. Please use "amplify add function" to create a new Layer';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}
const resourceQuestion: InputQuestion = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const parametersFileName = 'lex-params.json';
const cfnParametersFilename = 'parameters.json';
const serviceName = 'Lex';
const fuzzy = require('fuzzy');
import { ResourceDoesNotExistError } from 'amplify-cli-core';
import { ResourceDoesNotExistError, exitOnNextTick } from 'amplify-cli-core';

async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
return configure(context, defaultValuesFilename, serviceMetadata);
Expand All @@ -31,7 +31,7 @@ function updateWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const errMessage = 'No resources to update. You need to add a resource.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}
const resources = Object.keys(lexResources);
const question = [
Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-notifications/lib/channel-APNS.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const inquirer = require('inquirer');
const ora = require('ora');
const fs = require('fs-extra');

const { exitOnNextTick } = require('amplify-cli-core');
const channelName = 'APNS';
const spinner = ora('');

Expand Down Expand Up @@ -72,7 +72,7 @@ async function enable(context, successMessage) {
} catch (err) {
context.print.error(err.message);
context.usageData.emitError(err);
process.exit(1);
exitOnNextTick(1);
}

spinner.start('Updating APNS Channel.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const storageCategory = 'storage';
const parametersFileName = 'parameters.json';
const amplifyMetaFilename = 'amplify-meta.json';
const s3CloudFormationTemplateFile = 's3-cloudformation-template.json';
const { ResoureNotFoundError } = require('amplify-cli-core');
const { ResoureNotFoundError, exitOnNextTick } = require('amplify-cli-core');
module.exports = {
name: subcommand,
run: async context => {
Expand All @@ -21,7 +21,7 @@ module.exports = {
const projectStorage = projectDetails.amplifyMeta.storage;
if (!projectStorage) {
context.usageData.emitError(new ResoureNotFoundError('Project storage not found'));
process.exit(0);
exitOnNextTick(0);
return;
}
const keys = Object.keys(projectStorage);
Expand All @@ -34,7 +34,7 @@ module.exports = {

if (s3ResourceName === '') {
context.usageData.emitError(new ResoureNotFoundError('S3 Resource does not exist'));
process.exit(0);
exitOnNextTick(0);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/amplify-category-predictions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { promptConsoleSupportedCategory } from './provider-utils/supportedPredic
const predictionsConsole = require('./provider-utils/awscloudformation/index');
const inquirer = require('inquirer');
const path = require('path');
import { ResourceDoesNotExistError } from 'amplify-cli-core';
import { ResourceDoesNotExistError, exitOnNextTick } from 'amplify-cli-core';

const category = 'predictions';

Expand All @@ -30,7 +30,7 @@ async function console(context) {
const errMessage = `No ${result.category} console supported resource found.`;
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
return;
}
let resourceObj = predictionsResources[0].value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import open from 'open';

const path = require('path');
const chalk = require('chalk');
const { NotImplementedError, ResourceDoesNotExistError } = require('amplify-cli-core');
const { NotImplementedError, ResourceDoesNotExistError, exitOnNextTick } = require('amplify-cli-core');
const parametersFileName = 'parameters.json';
const prefixForAdminTrigger = 'protected/predictions/index-faces/admin';

Expand All @@ -26,7 +26,7 @@ function updateResource(context, predictionsCategoryFilename) {
const errMessage = 'Update functionality not available for this service';
context.print.error(errMessage);
context.usageData.emitError(new NotImplementedError(errMessage));
process.exit(0);
exitOnNextTick(0);
}

return updateWalkthrough(context).then(resource => resource.resourceName);
Expand Down Expand Up @@ -93,7 +93,7 @@ async function printRekognitionUploadUrl(context, resourceName, amplifyMeta, sho
const errMessage = 'Push the resources to the cloud using `amplify push` command.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
}
}
});
Expand All @@ -102,7 +102,7 @@ async function printRekognitionUploadUrl(context, resourceName, amplifyMeta, sho
const errMessage = 'Push the resources to the cloud using `amplify push` command.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
exitOnNextTick(0);
return;
}
const region = amplifyMeta.providers.awscloudformation.Region;
Expand All @@ -113,7 +113,7 @@ async function printRekognitionUploadUrl(context, resourceName, amplifyMeta, sho
// !showOnAmplifyStatus is used so that this message is not shown in amplify status scenario.
context.print.error(errMessage);
context.usageData.emitError(new NotImplementedError(errMessage));
process.exit(0);
exitOnNextTick(0);
}
}

Expand Down

0 comments on commit 33132f7

Please sign in to comment.