Skip to content

Commit

Permalink
add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
Amplifiyer committed Sep 10, 2024
1 parent 4ccd7bd commit d75a791
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-gorillas-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-cli': patch
---

throw user error when sandbox identifier validation fails
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions packages/cli/src/commands/sandbox/sandbox_command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { createSandboxSecretCommand } from './sandbox-secret/sandbox_secret_comm
import { ClientConfigGeneratorAdapter } from '../../client-config/client_config_generator_adapter.js';
import { CommandMiddleware } from '../../command_middleware.js';
import { PackageManagerController } from '@aws-amplify/plugin-types';
import { AmplifyUserError } from '@aws-amplify/platform-core';

mock.method(fsp, 'mkdir', () => Promise.resolve());

Expand Down Expand Up @@ -121,6 +122,27 @@ void describe('sandbox command', () => {
);
});

void it('throws AmplifyUserError if invalid identifier is provided', async () => {
const invalidIdentifier = 'invalid@';
const invalidIdentifierError = new AmplifyUserError(
'InvalidCommandInputError',
{
message: `Invalid --identifier provided: ${invalidIdentifier}`,
resolution:
'Use an identifier that matches [a-zA-Z0-9-] and is less than 15 characters.',
}
);
await assert.rejects(
() =>
commandRunner.runCommand(`sandbox --identifier ${invalidIdentifier}`), // invalid identifier
(err: TestCommandError) => {
assert.deepStrictEqual(err.error, invalidIdentifierError);
return true;
}
);
assert.equal(sandboxStartMock.mock.callCount(), 0);
});

void it('shows available options in help output', async () => {
const output = await commandRunner.runCommand('sandbox --help');
assert.match(output, /--identifier/);
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/commands/sandbox/sandbox_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CommandMiddleware } from '../../command_middleware.js';
import { SandboxCommandGlobalOptions } from './option_types.js';
import { ArgumentsKebabCase } from '../../kebab_case.js';
import { PackageManagerController } from '@aws-amplify/plugin-types';
import { AmplifyUserError } from '@aws-amplify/platform-core';

export type SandboxCommandOptionsKebabCase = ArgumentsKebabCase<
{
Expand Down Expand Up @@ -254,9 +255,11 @@ export class SandboxCommand
if (argv.identifier) {
const identifierRegex = /^[a-zA-Z0-9-]{1,15}$/;
if (!argv.identifier.match(identifierRegex)) {
throw new Error(
`--identifier should match [a-zA-Z0-9-] and be less than 15 characters.`
);
throw new AmplifyUserError('InvalidCommandInputError', {
message: `Invalid --identifier provided: ${argv.identifier}`,
resolution:
'Use an identifier that matches [a-zA-Z0-9-] and is less than 15 characters.',
});
}
}
return true;
Expand Down

0 comments on commit d75a791

Please sign in to comment.