Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/aws-cdk-lib/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const enableNoThrowDefaultErrorIn = [
'aws-elasticloadbalancingv2',
'aws-elasticloadbalancingv2-actions',
'aws-elasticloadbalancingv2-targets',
'aws-fsx',
'aws-kinesisfirehose',
'aws-lambda',
'aws-logs',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UnscopedValidationError } from '../../core';

/**
* Properties required for setting up a daily automatic backup time.
*/
Expand Down Expand Up @@ -59,10 +61,10 @@ export class DailyAutomaticBackupStartTime {
*/
private validate(hour: number, minute: number) {
if (!Number.isInteger(hour) || hour < 0 || hour > 23) {
throw new Error(`dailyAutomaticBackupStartTime hour must be an integer between 0 and 24. received: ${hour}`);
throw new UnscopedValidationError(`dailyAutomaticBackupStartTime hour must be an integer between 0 and 24. received: ${hour}`);
}
if (!Number.isInteger(minute) || minute < 0 || minute > 59) {
throw new Error(`dailyAutomaticBackupStartTime minute must be an integer between 0 and 59. received: ${minute}`);
throw new UnscopedValidationError(`dailyAutomaticBackupStartTime minute must be an integer between 0 and 59. received: ${minute}`);
}
}
}
50 changes: 25 additions & 25 deletions packages/aws-cdk-lib/aws-fsx/lib/lustre-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FileSystemAttributes, FileSystemBase, FileSystemProps, IFileSystem, Sto
import { CfnFileSystem } from './fsx.generated';
import { LustreMaintenanceTime } from './maintenance-time';
import { Connections, ISecurityGroup, ISubnet, Port, SecurityGroup } from '../../aws-ec2';
import { Aws, Duration, Token } from '../../core';
import { Aws, Duration, Token, ValidationError } from '../../core';
import { addConstructMetadata } from '../../core/lib/metadata-resource';

/**
Expand Down Expand Up @@ -388,7 +388,7 @@ export class LustreFileSystem extends FileSystemBase {
if (!driveCacheType) return;

if (deploymentType !== LustreDeploymentType.PERSISTENT_1 || storageType !== StorageType.HDD) {
throw new Error(`driveCacheType can only be set for PERSISTENT_1 HDD storage type, got: ${deploymentType} and ${storageType}`);
throw new ValidationError(`driveCacheType can only be set for PERSISTENT_1 HDD storage type, got: ${deploymentType} and ${storageType}`, this);
}
}

Expand All @@ -399,7 +399,7 @@ export class LustreFileSystem extends FileSystemBase {
if (!storageType) return;

if (storageType === StorageType.HDD && deploymentType !== LustreDeploymentType.PERSISTENT_1) {
throw new Error(`Storage type HDD is only supported for PERSISTENT_1 deployment type, got: ${deploymentType}`);
throw new ValidationError(`Storage type HDD is only supported for PERSISTENT_1 deployment type, got: ${deploymentType}`, this);
}
}

Expand All @@ -413,7 +413,7 @@ export class LustreFileSystem extends FileSystemBase {

if (fileSystemTypeVersion === FileSystemTypeVersion.V_2_10) {
if (!deploymentType.startsWith('SCRATCH') && deploymentType !== LustreDeploymentType.PERSISTENT_1) {
throw new Error('fileSystemTypeVersion V_2_10 is only supported for SCRATCH and PERSISTENT_1 deployment types');
throw new ValidationError('fileSystemTypeVersion V_2_10 is only supported for SCRATCH and PERSISTENT_1 deployment types', this);
}
}

Expand All @@ -426,10 +426,10 @@ export class LustreFileSystem extends FileSystemBase {
private validateAutoImportPolicy(deploymentType: LustreDeploymentType, importPath?: string, autoImportPolicy?: LustreAutoImportPolicy): void {
if (autoImportPolicy === undefined) { return; }
if (importPath === undefined) {
throw new Error('autoImportPolicy requires importPath to be defined');
throw new ValidationError('autoImportPolicy requires importPath to be defined', this);
}
if (deploymentType === LustreDeploymentType.PERSISTENT_2) {
throw new Error('autoImportPolicy is not supported with PERSISTENT_2 deployments');
throw new ValidationError('autoImportPolicy is not supported with PERSISTENT_2 deployments', this);
}
}

Expand All @@ -439,19 +439,19 @@ export class LustreFileSystem extends FileSystemBase {
private validateExportPath(exportPath?: string, importPath?: string): void {
if (exportPath === undefined) { return; }
if (importPath === undefined) {
throw new Error('Cannot define an export path without also defining an import path');
throw new ValidationError('Cannot define an export path without also defining an import path', this);
}

if (Token.isUnresolved(exportPath) && Token.isUnresolved(importPath)) { return; }

if (Token.isUnresolved(importPath) !== Token.isUnresolved(exportPath)) {
throw new Error('The importPath and exportPath must each be Tokens or not Tokens, you cannot use a mix');
throw new ValidationError('The importPath and exportPath must each be Tokens or not Tokens, you cannot use a mix', this);
}
if (!exportPath.startsWith(importPath)) {
throw new Error(`The export path "${exportPath}" is invalid. Expecting the format: s3://{IMPORT_PATH}/optional-prefix`);
throw new ValidationError(`The export path "${exportPath}" is invalid. Expecting the format: s3://{IMPORT_PATH}/optional-prefix`, this);
}
if (exportPath.length > 900) {
throw new Error(`The export path "${exportPath}" exceeds the maximum length of 900 characters`);
throw new ValidationError(`The export path "${exportPath}" exceeds the maximum length of 900 characters`, this);
}
}

Expand All @@ -462,7 +462,7 @@ export class LustreFileSystem extends FileSystemBase {
if (importedFileChunkSize === undefined) { return; }

if (importedFileChunkSize < 1 || importedFileChunkSize > 512000) {
throw new Error(`importedFileChunkSize cannot be ${importedFileChunkSize} MiB. It must be a value from 1 to 512,000 MiB`);
throw new ValidationError(`importedFileChunkSize cannot be ${importedFileChunkSize} MiB. It must be a value from 1 to 512,000 MiB`, this);
}
}

Expand All @@ -475,10 +475,10 @@ export class LustreFileSystem extends FileSystemBase {
const regexp = /^s3:\/\//;

if (importPath.search(regexp) === -1) {
throw new Error(`The import path "${importPath}" is invalid. Expecting the format: s3://{BUCKET_NAME}/optional-prefix`);
throw new ValidationError(`The import path "${importPath}" is invalid. Expecting the format: s3://{BUCKET_NAME}/optional-prefix`, this);
}
if (importPath.length > 900) {
throw new Error(`The import path "${importPath}" exceeds the maximum length of 900 characters`);
throw new ValidationError(`The import path "${importPath}" exceeds the maximum length of 900 characters`, this);
}
}

Expand All @@ -495,21 +495,21 @@ export class LustreFileSystem extends FileSystemBase {
if (perUnitStorageThroughput === undefined) { return; }

if (deploymentType !== LustreDeploymentType.PERSISTENT_1 && deploymentType !== LustreDeploymentType.PERSISTENT_2) {
throw new Error('perUnitStorageThroughput can only be set for the PERSISTENT_1/PERSISTENT_2 deployment types, received: ' + deploymentType);
throw new ValidationError('perUnitStorageThroughput can only be set for the PERSISTENT_1/PERSISTENT_2 deployment types, received: ' + deploymentType, this);
}

if (deploymentType === LustreDeploymentType.PERSISTENT_1) {
if (storageType === StorageType.HDD && ![12, 40].includes(perUnitStorageThroughput)) {
throw new Error(`perUnitStorageThroughput must be 12 or 40 MB/s/TiB for PERSISTENT_1 HDD storage, got: ${perUnitStorageThroughput}`);
throw new ValidationError(`perUnitStorageThroughput must be 12 or 40 MB/s/TiB for PERSISTENT_1 HDD storage, got: ${perUnitStorageThroughput}`, this);
}
if ((storageType === undefined || storageType === StorageType.SSD) && ![50, 100, 200].includes(perUnitStorageThroughput)) {
throw new Error('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB for PERSISTENT_1 SSD storage, got: ' + perUnitStorageThroughput);
throw new ValidationError('perUnitStorageThroughput must be 50, 100, or 200 MB/s/TiB for PERSISTENT_1 SSD storage, got: ' + perUnitStorageThroughput, this);
}
}

if (deploymentType === LustreDeploymentType.PERSISTENT_2) {
if (![125, 250, 500, 1000].includes(perUnitStorageThroughput)) {
throw new Error(`perUnitStorageThroughput must be 125, 250, 500 or 1000 MB/s/TiB for PERSISTENT_2 deployment type, got: ${perUnitStorageThroughput}`);
throw new ValidationError(`perUnitStorageThroughput must be 125, 250, 500 or 1000 MB/s/TiB for PERSISTENT_2 deployment type, got: ${perUnitStorageThroughput}`, this);
}
}
}
Expand All @@ -527,7 +527,7 @@ export class LustreFileSystem extends FileSystemBase {
): void {
if (deploymentType === LustreDeploymentType.SCRATCH_1) {
if (![1200, 2400, 3600].includes(storageCapacity) && storageCapacity % 3600 !== 0) {
throw new Error(`storageCapacity must be 1,200, 2,400, 3,600, or a multiple of 3,600 for SCRATCH_1 deployment type, got ${storageCapacity}.`);
throw new ValidationError(`storageCapacity must be 1,200, 2,400, 3,600, or a multiple of 3,600 for SCRATCH_1 deployment type, got ${storageCapacity}.`, this);
}
}

Expand All @@ -536,21 +536,21 @@ export class LustreFileSystem extends FileSystemBase {
|| deploymentType === LustreDeploymentType.SCRATCH_2
) {
if (![1200, 2400].includes(storageCapacity) && storageCapacity % 2400 !== 0) {
throw new Error(`storageCapacity must be 1,200, 2,400, or a multiple of 2,400 for SCRATCH_2 and PERSISTENT_2 deployment types, got ${storageCapacity}`);
throw new ValidationError(`storageCapacity must be 1,200, 2,400, or a multiple of 2,400 for SCRATCH_2 and PERSISTENT_2 deployment types, got ${storageCapacity}`, this);
}
}

if (deploymentType === LustreDeploymentType.PERSISTENT_1) {
if (storageType === StorageType.HDD) {
if (perUnitStorageThroughput === 12 && storageCapacity % 6000 !== 0) {
throw new Error(`storageCapacity must be a multiple of 6,000 for PERSISTENT_1 HDD storage with 12 MB/s/TiB throughput, got ${storageCapacity}`);
throw new ValidationError(`storageCapacity must be a multiple of 6,000 for PERSISTENT_1 HDD storage with 12 MB/s/TiB throughput, got ${storageCapacity}`, this);
}
if (perUnitStorageThroughput === 40 && storageCapacity % 1800 !== 0) {
throw new Error(`storageCapacity must be a multiple of 1,800 for PERSISTENT_1 HDD storage with 40 MB/s/TiB throughput, got ${storageCapacity}`);
throw new ValidationError(`storageCapacity must be a multiple of 1,800 for PERSISTENT_1 HDD storage with 40 MB/s/TiB throughput, got ${storageCapacity}`, this);
}
} else {
if (![1200, 2400].includes(storageCapacity) && storageCapacity % 2400 !== 0) {
throw new Error(`storageCapacity must be 1,200, 2,400, or a multiple of 2,400 for PERSISTENT_1 SSD storage, got ${storageCapacity}`);
throw new ValidationError(`storageCapacity must be 1,200, 2,400, or a multiple of 2,400 for PERSISTENT_1 SSD storage, got ${storageCapacity}`, this);
}
}
}
Expand All @@ -564,11 +564,11 @@ export class LustreFileSystem extends FileSystemBase {
const automaticBackupRetentionDays = automaticBackupRetention.toDays();

if ([LustreDeploymentType.SCRATCH_1, LustreDeploymentType.SCRATCH_2].includes(deploymentType) && automaticBackupRetentionDays > 0) {
throw new Error('automatic backups is not supported on scratch file systems');
throw new ValidationError('automatic backups is not supported on scratch file systems', this);
}

if (automaticBackupRetentionDays > 90) {
throw new Error(`automaticBackupRetention period must be between 0 and 90 days. received: ${automaticBackupRetentionDays}`);
throw new ValidationError(`automaticBackupRetention period must be between 0 and 90 days. received: ${automaticBackupRetentionDays}`, this);
}
}
}
Expand All @@ -583,7 +583,7 @@ export class LustreFileSystem extends FileSystemBase {
const automaticBackupDisabled = !automaticBackupRetention || automaticBackupRetention?.toDays() === Duration.days(0).toDays();

if (dailyAutomaticBackupStartTime && automaticBackupDisabled) {
throw new Error('automaticBackupRetention period must be set a non-zero day when dailyAutomaticBackupStartTime is set');
throw new ValidationError('automaticBackupRetention period must be set a non-zero day when dailyAutomaticBackupStartTime is set', this);
}
}
}
6 changes: 4 additions & 2 deletions packages/aws-cdk-lib/aws-fsx/lib/maintenance-time.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UnscopedValidationError } from '../../core';

/**
* Enum for representing all the days of the week
*/
Expand Down Expand Up @@ -97,10 +99,10 @@ export class LustreMaintenanceTime {
*/
private validate(hour: number, minute: number) {
if (!Number.isInteger(hour) || hour < 0 || hour > 23) {
throw new Error('Maintenance time hour must be an integer between 0 and 23');
throw new UnscopedValidationError('Maintenance time hour must be an integer between 0 and 23');
}
if (!Number.isInteger(minute) || minute < 0 || minute > 59) {
throw new Error('Maintenance time minute must be an integer between 0 and 59');
throw new UnscopedValidationError('Maintenance time minute must be an integer between 0 and 59');
}
}
}