diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index ffebf3c7e4164..f86df8e8e501d 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -50,6 +50,7 @@ const enableNoThrowDefaultErrorIn = [ 'aws-docdb', 'aws-dynamodb', 'aws-ecr', + 'aws-ecr-assets', 'aws-efs', 'aws-elasticloadbalancing', 'aws-elasticloadbalancingv2', diff --git a/packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts b/packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts index 5069230b60972..a40a1ccb1a557 100644 --- a/packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts +++ b/packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { Construct } from 'constructs'; import { FingerprintOptions, FollowMode, IAsset } from '../../assets'; import * as ecr from '../../aws-ecr'; -import { Annotations, AssetStaging, FeatureFlags, FileFingerprintOptions, IgnoreMode, Stack, SymlinkFollowMode, Token, Stage, CfnResource } from '../../core'; +import { Annotations, AssetStaging, FeatureFlags, FileFingerprintOptions, IgnoreMode, Stack, SymlinkFollowMode, Token, Stage, CfnResource, ValidationError, UnscopedValidationError } from '../../core'; import * as cxapi from '../../cx-api'; /** @@ -435,14 +435,14 @@ export class DockerImageAsset extends Construct implements IAsset { // resolve full path const dir = path.resolve(props.directory); if (!fs.existsSync(dir)) { - throw new Error(`Cannot find image directory at ${dir}`); + throw new ValidationError(`Cannot find image directory at ${dir}`, this); } // validate the docker file exists this.dockerfilePath = props.file || 'Dockerfile'; const file = path.join(dir, this.dockerfilePath); if (!fs.existsSync(file)) { - throw new Error(`Cannot find file at ${file}`); + throw new ValidationError(`Cannot find file at ${file}`, this); } const defaultIgnoreMode = FeatureFlags.of(this).isEnabled(cxapi.DOCKER_IGNORE_SUPPORT) @@ -582,7 +582,7 @@ export class DockerImageAsset extends Construct implements IAsset { function validateProps(props: DockerImageAssetProps) { for (const [key, value] of Object.entries(props)) { if (Token.isUnresolved(value)) { - throw new Error(`Cannot use Token as value of '${key}': this value is used before deployment starts`); + throw new UnscopedValidationError(`Cannot use Token as value of '${key}': this value is used before deployment starts`); } } @@ -593,7 +593,7 @@ function validateProps(props: DockerImageAssetProps) { function validateBuildProps(buildPropName: string, buildProps?: { [key: string]: string }) { for (const [key, value] of Object.entries(buildProps || {})) { if (Token.isUnresolved(key) || Token.isUnresolved(value)) { - throw new Error(`Cannot use tokens in keys or values of "${buildPropName}" since they are needed before deployment`); + throw new UnscopedValidationError(`Cannot use tokens in keys or values of "${buildPropName}" since they are needed before deployment`); } } } diff --git a/packages/aws-cdk-lib/aws-ecr-assets/lib/tarball-asset.ts b/packages/aws-cdk-lib/aws-ecr-assets/lib/tarball-asset.ts index 3265b43719529..676dbbd80d928 100644 --- a/packages/aws-cdk-lib/aws-ecr-assets/lib/tarball-asset.ts +++ b/packages/aws-cdk-lib/aws-ecr-assets/lib/tarball-asset.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { Construct } from 'constructs'; import { IAsset } from '../../assets'; import * as ecr from '../../aws-ecr'; -import { AssetStaging, Stack, Stage } from '../../core'; +import { AssetStaging, Stack, Stage, ValidationError } from '../../core'; /** * Options for TarballImageAsset @@ -60,7 +60,7 @@ export class TarballImageAsset extends Construct implements IAsset { super(scope, id); if (!fs.existsSync(props.tarballFile)) { - throw new Error(`Cannot find file at ${props.tarballFile}`); + throw new ValidationError(`Cannot find file at ${props.tarballFile}`, this); } const stagedTarball = new AssetStaging(this, 'Staging', { sourcePath: props.tarballFile });