From 688adce9d7a82fe47e60330acfc5038ca51df19e Mon Sep 17 00:00:00 2001 From: Kaizen Conroy Date: Thu, 20 Mar 2025 18:09:42 -0400 Subject: [PATCH] feat(codecommit): throw `ValidationErrors` instead of untyped Errors --- packages/aws-cdk-lib/.eslintrc.js | 1 + packages/aws-cdk-lib/aws-codecommit/lib/code.ts | 9 +++++---- packages/aws-cdk-lib/aws-codecommit/lib/repository.ts | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index 283ad93834c89..4d876446684d3 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -41,6 +41,7 @@ const enableNoThrowDefaultErrorIn = [ 'aws-cloudtrail', 'aws-cloudwatch', 'aws-cloudwatch-actions', + 'aws-codecommit', 'aws-ecr', 'aws-elasticloadbalancing', 'aws-elasticloadbalancingv2', diff --git a/packages/aws-cdk-lib/aws-codecommit/lib/code.ts b/packages/aws-cdk-lib/aws-codecommit/lib/code.ts index bc4f4c3f27025..aa68bd3646bde 100644 --- a/packages/aws-cdk-lib/aws-codecommit/lib/code.ts +++ b/packages/aws-cdk-lib/aws-codecommit/lib/code.ts @@ -3,6 +3,7 @@ import * as path from 'path'; import { Construct } from 'constructs'; import { CfnRepository } from './codecommit.generated'; import * as assets from '../../aws-s3-assets'; +import { UnscopedValidationError, ValidationError } from '../../core'; /** * Represents the structure to pass into the underlying CfnRepository class. @@ -28,7 +29,7 @@ export abstract class Code { const statResult = fs.statSync(resolvedPath); if (!statResult || !statResult.isDirectory()) { - throw new Error(`'${directoryPath}' needs to be a path to a directory (resolved to: '${resolvedPath }')`); + throw new UnscopedValidationError(`'${directoryPath}' needs to be a path to a directory (resolved to: '${resolvedPath }')`); } return new PathResolvedCode(resolvedPath, branch); @@ -44,7 +45,7 @@ export abstract class Code { const statResult = fs.statSync(resolvedPath); if (!statResult || !statResult.isFile()) { - throw new Error(`'${filePath}' needs to be a path to a ZIP file (resolved to: '${resolvedPath }')`); + throw new UnscopedValidationError(`'${filePath}' needs to be a path to a ZIP file (resolved to: '${resolvedPath }')`); } return new PathResolvedCode(resolvedPath, branch); @@ -86,9 +87,9 @@ class AssetCode extends Code { super(); } - public bind(_scope: Construct): CodeConfig { + public bind(scope: Construct): CodeConfig { if (!this.asset.isZipArchive) { - throw new Error('Asset must be a .zip file or a directory (resolved to: ' + this.asset.assetPath + ' )'); + throw new ValidationError('Asset must be a .zip file or a directory (resolved to: ' + this.asset.assetPath + ' )', scope); } return { diff --git a/packages/aws-cdk-lib/aws-codecommit/lib/repository.ts b/packages/aws-cdk-lib/aws-codecommit/lib/repository.ts index a15de16f35b9a..ab5c1414985b2 100644 --- a/packages/aws-cdk-lib/aws-codecommit/lib/repository.ts +++ b/packages/aws-cdk-lib/aws-codecommit/lib/repository.ts @@ -5,7 +5,7 @@ import * as notifications from '../../aws-codestarnotifications'; import * as events from '../../aws-events'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; -import { ArnFormat, IResource, Lazy, Resource, Stack } from '../../core'; +import { ArnFormat, IResource, Lazy, Resource, Stack, ValidationError } from '../../core'; import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource'; /** @@ -605,7 +605,7 @@ export class Repository extends RepositoryBase { } if (this.triggers.find(prop => prop.name === name)) { - throw new Error(`Unable to set repository trigger named ${name} because trigger names must be unique`); + throw new ValidationError(`Unable to set repository trigger named ${name} because trigger names must be unique`, this); } this.triggers.push({