-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate env to new error handling (#11053)
* chore: migrate env to new error handling * chore: update to use troubleshooting link shorthand method * chore: throw amplify error on BackendDeleteFault * chore: update pr to use troubleshooting link instead * chore: fix unused import * chore: moved error message to details section * fix: updated test to expect correct error type
- Loading branch information
Showing
11 changed files
with
214 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { $TSContext, pathManager } from 'amplify-cli-core'; | ||
import { run as init } from '../init'; | ||
import { $TSContext, pathManager, AmplifyError } from 'amplify-cli-core'; | ||
import fs from 'fs-extra'; | ||
import { run as init } from '../init'; | ||
|
||
export const run = async (context: $TSContext) => { | ||
/** | ||
* Executes the 'env add' command | ||
*/ | ||
export const run = async (context: $TSContext) : Promise<void> => { | ||
const amplifyMetaFilePath = pathManager.getAmplifyMetaFilePath(); | ||
if (!fs.existsSync(amplifyMetaFilePath)) { | ||
throw new Error( | ||
'Your workspace is not configured to modify the backend. If you wish to change this configuration, remove your `amplify` directory and pull the project again.', | ||
); | ||
throw new AmplifyError('ConfigurationError', { | ||
// eslint-disable-next-line spellcheck/spell-checker | ||
message: 'Your workspace is not configured to modify the backend.', | ||
resolution: 'If you wish to change this configuration, remove your `amplify` directory and pull the project again.', | ||
}); | ||
} | ||
await init(context); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,33 @@ | ||
import chalk from 'chalk'; | ||
import { JSONUtilities, $TSContext, UnknownArgumentError, exitOnNextTick } from 'amplify-cli-core'; | ||
import { JSONUtilities, $TSContext, AmplifyError } from 'amplify-cli-core'; | ||
import { printer } from 'amplify-prompts'; | ||
import { printEnvInfo } from '../helpers/envUtils'; | ||
|
||
export const run = async (context: $TSContext) => { | ||
/** | ||
* Executes the 'env get' command | ||
*/ | ||
export const run = async (context: $TSContext) : Promise<void> => { | ||
const envName = context.parameters.options.name; | ||
const allEnvs = context.amplify.getEnvDetails(); | ||
|
||
if (!envName) { | ||
const errMessage = 'You must pass in the name of the environment using the --name flag'; | ||
context.print.error(errMessage); | ||
context.usageData.emitError(new UnknownArgumentError(errMessage)); | ||
exitOnNextTick(1); | ||
throw new AmplifyError('EnvironmentNameError', { | ||
message: 'Environment name was not specified.', | ||
resolution: 'Pass in the name of the environment using the --name flag.', | ||
}); | ||
} | ||
if (!allEnvs[envName]) { | ||
throw new AmplifyError('EnvironmentNameError', { | ||
message: 'Environment name is invalid.', | ||
resolution: 'Run amplify env list to get a list of valid environments.', | ||
}); | ||
} | ||
|
||
const allEnvs = context.amplify.getEnvDetails(); | ||
|
||
if (context.parameters.options.json) { | ||
if (allEnvs[envName]) { | ||
context.print.fancy(JSONUtilities.stringify(allEnvs[envName])); | ||
} else { | ||
context.print.fancy(JSONUtilities.stringify({ error: `No environment found with name: '${envName}'` })); | ||
} | ||
printer.info(JSONUtilities.stringify(allEnvs[envName]) as string); | ||
return; | ||
} | ||
|
||
let envFound = false; | ||
|
||
Object.keys(allEnvs).forEach(env => { | ||
if (env === envName) { | ||
envFound = true; | ||
context.print.info(''); | ||
context.print.info(chalk.red(env)); | ||
printEnvInfo(context, env, allEnvs); | ||
} | ||
}); | ||
|
||
if (!envFound) { | ||
context.print.error('No environment found with the corresponding name provided'); | ||
} | ||
printer.blankLine(); | ||
printer.info(envName, 'red'); | ||
printEnvInfo(envName, allEnvs); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.