Skip to content

Commit

Permalink
Update profile error messages (#647)
Browse files Browse the repository at this point in the history
* Update profile error message and the profile configure URL

---------

Co-authored-by: Hoang Nguyen <hoangaz@amazon.com>
  • Loading branch information
hoangnbn and Hoang Nguyen committed Nov 15, 2023
1 parent 3a472c4 commit 869a849
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-brooms-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-cli': patch
---

Update profile error messages and a profile configure URL.
14 changes: 10 additions & 4 deletions packages/cli/src/command_middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ void describe('commandMiddleware', () => {
);
assert.fail('expect to throw error');
} catch (err) {
assert.match((err as Error).message, /region setting options/);
assert.match(
(err as Error).message,
/Failed to load default aws region/
);
}
});

Expand Down Expand Up @@ -147,7 +150,10 @@ void describe('commandMiddleware', () => {
);
assert.fail('expect to throw error');
} catch (err) {
assert.match((err as Error).message, /region setting options/);
assert.match(
(err as Error).message,
/Failed to load default aws region/
);
}
});

Expand Down Expand Up @@ -181,13 +187,13 @@ void describe('commandMiddleware', () => {

try {
await commandMiddleware.ensureAwsCredentialAndRegion({
profile: 'someInvalidProfile',
profile: testProfile,
} as ArgumentsCamelCase<{ profile: string | undefined }>);
assert.fail('expect to throw error');
} catch (err) {
assert.match(
(err as Error).message,
/Failed to load aws credentials for profile/
/Failed to load aws region for profile/
);
}
});
Expand Down
25 changes: 19 additions & 6 deletions packages/cli/src/command_middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { loadConfig } from '@smithy/node-config-provider';
import { NODE_REGION_CONFIG_OPTIONS } from '@aws-sdk/region-config-resolver';
import { InvalidCredentialError } from './error/credential_error.js';

export const profileSetupInstruction = `To configure a new Amplify profile, use "amplify configure profile".${EOL}To update an existing profile, use "aws configure"`;
export const profileSetupInstruction = `To configure a new Amplify profile, use "amplify configure profile".`;

/**
* Contains middleware functions.
Expand All @@ -32,10 +32,15 @@ export class CommandMiddleware {
} catch (err) {
let errMsg: string;
if (argv.profile) {
errMsg = `Failed to load aws credentials for profile '${argv.profile}'.${EOL}${profileSetupInstruction}`;
errMsg = `Failed to load aws credentials for profile '${
argv.profile
}': ${(err as Error).message}.${EOL}`;
} else {
errMsg = `Failed to load default aws credentials.${EOL}Please refer to https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html.${EOL}${profileSetupInstruction}`;
errMsg = `Failed to load default aws credentials: ${
(err as Error).message
}.${EOL}`;
}
errMsg += profileSetupInstruction;
throw new InvalidCredentialError(errMsg, { cause: err });
}

Expand All @@ -45,9 +50,17 @@ export class CommandMiddleware {
ignoreCache: true,
})();
} catch (err) {
const errMsg = `${
(err as Error).message
}. Please refer to this page for region setting options:${EOL}https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-region.html${EOL}${profileSetupInstruction}`;
let errMsg: string;
if (argv.profile) {
errMsg = `Failed to load aws region for profile '${argv.profile}': ${
(err as Error).message
}.${EOL}`;
} else {
errMsg = `Failed to load default aws region: ${
(err as Error).message
}.${EOL}`;
}
errMsg += profileSetupInstruction;
throw new InvalidCredentialError(errMsg, { cause: err });
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void describe('configure command', () => {
assert.equal(mockOpen.mock.callCount(), 1);
assert.equal(
mockOpen.mock.calls[0].arguments[0],
'https://docs.amplify.aws/cli/start/install/'
'https://docs.amplify.aws/gen2/start/configure-account'
);
assert.equal(mockAppendAWSFiles.mock.callCount(), 1);
assert.deepStrictEqual(mockAppendAWSFiles.mock.calls[0].arguments[0], {
Expand Down
15 changes: 7 additions & 8 deletions packages/cli/src/commands/configure/configure_profile_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { Open } from '../open/open.js';
import { ArgumentsKebabCase } from '../../kebab_case.js';
import { ProfileController } from './profile_controller.js';

const amplifyInstallUrl = 'https://docs.amplify.aws/cli/start/install/';
const awsConfigureUrl =
'https://docs.aws.amazon.com/cli/latest/userguide/getting-started-quickstart.html#getting-started-quickstart-new-command';
const configureAccountUrl =
'https://docs.amplify.aws/gen2/start/configure-account';

const profileSetupInstruction = `Follow the instructions at ${configureAccountUrl}${EOL}to configure Amplify IAM user and credentials.${EOL}`;

/**
* Command to configure AWS Amplify profile.
Expand Down Expand Up @@ -44,7 +45,7 @@ export class ConfigureProfileCommand
);
if (profileExists) {
Printer.print(
`Profile '${profileName}' already exists!${EOL}Follow the instructions at ${amplifyInstallUrl} to configure an Amplify IAM User.${EOL}Use "aws configure" to complete the profile setup:${EOL}${awsConfigureUrl}${EOL}`
`Profile '${profileName}' already exists!${EOL}${profileSetupInstruction}`
);
return;
}
Expand All @@ -53,11 +54,9 @@ export class ConfigureProfileCommand
});

if (!hasIAMUser) {
Printer.print(
`Follow the instructions at ${amplifyInstallUrl}${EOL}to configure Amplify IAM user and credentials.${EOL}`
);
Printer.print(profileSetupInstruction);

await Open.open(amplifyInstallUrl, { wait: false });
await Open.open(configureAccountUrl, { wait: false });
await AmplifyPrompter.input({
message: `Hit [enter] when complete`,
});
Expand Down

0 comments on commit 869a849

Please sign in to comment.