diff --git a/.changeset/small-gorillas-remain.md b/.changeset/small-gorillas-remain.md new file mode 100644 index 0000000000..03d12139de --- /dev/null +++ b/.changeset/small-gorillas-remain.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/backend-cli': patch +--- + +throw user error when sandbox identifier validation fails diff --git a/package-lock.json b/package-lock.json index d1f0b2600b..06b7cca03b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24670,7 +24670,7 @@ }, "packages/ai-constructs": { "name": "@aws-amplify/ai-constructs", - "version": "0.1.1", + "version": "0.1.2", "license": "Apache-2.0", "dependencies": { "@aws-amplify/plugin-types": "^1.0.1", @@ -24869,7 +24869,7 @@ }, "packages/backend-secret": { "name": "@aws-amplify/backend-secret", - "version": "1.1.0", + "version": "1.1.1", "license": "Apache-2.0", "dependencies": { "@aws-amplify/platform-core": "^1.0.5", @@ -25511,11 +25511,11 @@ }, "packages/sandbox": { "name": "@aws-amplify/sandbox", - "version": "1.2.0", + "version": "1.2.1", "license": "Apache-2.0", "dependencies": { "@aws-amplify/backend-deployer": "^1.1.0", - "@aws-amplify/backend-secret": "^1.1.0", + "@aws-amplify/backend-secret": "^1.1.1", "@aws-amplify/cli-core": "^1.1.2", "@aws-amplify/client-config": "^1.1.3", "@aws-amplify/deployed-backend-client": "^1.3.0", diff --git a/packages/cli/src/commands/sandbox/sandbox_command.test.ts b/packages/cli/src/commands/sandbox/sandbox_command.test.ts index a240f33d59..7b653d877c 100644 --- a/packages/cli/src/commands/sandbox/sandbox_command.test.ts +++ b/packages/cli/src/commands/sandbox/sandbox_command.test.ts @@ -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 { AmplifyError } from '@aws-amplify/platform-core'; mock.method(fsp, 'mkdir', () => Promise.resolve()); @@ -121,6 +122,24 @@ void describe('sandbox command', () => { ); }); + void it('throws AmplifyUserError if invalid identifier is provided', async () => { + const invalidIdentifier = 'invalid@'; + await assert.rejects( + () => + commandRunner.runCommand(`sandbox --identifier ${invalidIdentifier}`), // invalid identifier + (err: TestCommandError) => { + assert.ok(err.error instanceof AmplifyError); + assert.strictEqual( + err.error.message, + 'Invalid --identifier provided: invalid@' + ); + assert.strictEqual(err.error.name, 'InvalidCommandInputError'); + 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/); diff --git a/packages/cli/src/commands/sandbox/sandbox_command.ts b/packages/cli/src/commands/sandbox/sandbox_command.ts index 1da7519f6a..356d0a8eb6 100644 --- a/packages/cli/src/commands/sandbox/sandbox_command.ts +++ b/packages/cli/src/commands/sandbox/sandbox_command.ts @@ -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< { @@ -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; diff --git a/scripts/components/api-changes-validator/test-resources/test-projects/with-breaks/class-break-constructor/expected-error-message.txt b/scripts/components/api-changes-validator/test-resources/test-projects/with-breaks/class-break-constructor/expected-error-message.txt index 5dce9746df..a20179f04b 100644 --- a/scripts/components/api-changes-validator/test-resources/test-projects/with-breaks/class-break-constructor/expected-error-message.txt +++ b/scripts/components/api-changes-validator/test-resources/test-projects/with-breaks/class-break-constructor/expected-error-message.txt @@ -5,5 +5,6 @@ index.ts(23,18): error TS2558: Expected 1 type arguments, but got 2. index.ts(24,18): error TS2558: Expected 1 type arguments, but got 2. index.ts(36,34): error TS2554: Expected 1 arguments, but got 2. index.ts(42,34): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'number | undefined'. + Type 'string' is not assignable to type 'number'. index.ts(47,26): error TS2558: Expected 1 type arguments, but got 2. index.ts(48,26): error TS2558: Expected 1 type arguments, but got 2.