Skip to content

Commit f28eae2

Browse files
authored
feat(codecommit): throw ValidationErrors instead of untyped Errors (#33854)
### Issue # (if applicable) Relates to #32569 ### Reason for this change untyped Errors are not recommended ### Description of changes ValidationErrors everywhere ### Describe any new or updated permissions being added None ### Description of how you validated changes Existing tests. Exemptions granted as this is a refactor of existing code. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b6b91dd commit f28eae2

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

packages/aws-cdk-lib/.eslintrc.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ const enableNoThrowDefaultErrorIn = [
4141
'aws-cloudwatch-actions',
4242
'aws-codeartifact',
4343
'aws-codebuild',
44-
'aws-cognito',
44+
'aws-codecommit',
4545
'aws-codedeploy',
46+
'aws-cognito',
4647
'aws-ecr',
4748
'aws-elasticloadbalancing',
4849
'aws-elasticloadbalancingv2',

packages/aws-cdk-lib/aws-codecommit/lib/code.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'path';
33
import { Construct } from 'constructs';
44
import { CfnRepository } from './codecommit.generated';
55
import * as assets from '../../aws-s3-assets';
6+
import { UnscopedValidationError, ValidationError } from '../../core';
67

78
/**
89
* Represents the structure to pass into the underlying CfnRepository class.
@@ -28,7 +29,7 @@ export abstract class Code {
2829

2930
const statResult = fs.statSync(resolvedPath);
3031
if (!statResult || !statResult.isDirectory()) {
31-
throw new Error(`'${directoryPath}' needs to be a path to a directory (resolved to: '${resolvedPath }')`);
32+
throw new UnscopedValidationError(`'${directoryPath}' needs to be a path to a directory (resolved to: '${resolvedPath }')`);
3233
}
3334

3435
return new PathResolvedCode(resolvedPath, branch);
@@ -44,7 +45,7 @@ export abstract class Code {
4445

4546
const statResult = fs.statSync(resolvedPath);
4647
if (!statResult || !statResult.isFile()) {
47-
throw new Error(`'${filePath}' needs to be a path to a ZIP file (resolved to: '${resolvedPath }')`);
48+
throw new UnscopedValidationError(`'${filePath}' needs to be a path to a ZIP file (resolved to: '${resolvedPath }')`);
4849
}
4950

5051
return new PathResolvedCode(resolvedPath, branch);
@@ -86,9 +87,9 @@ class AssetCode extends Code {
8687
super();
8788
}
8889

89-
public bind(_scope: Construct): CodeConfig {
90+
public bind(scope: Construct): CodeConfig {
9091
if (!this.asset.isZipArchive) {
91-
throw new Error('Asset must be a .zip file or a directory (resolved to: ' + this.asset.assetPath + ' )');
92+
throw new ValidationError('Asset must be a .zip file or a directory (resolved to: ' + this.asset.assetPath + ' )', scope);
9293
}
9394

9495
return {

packages/aws-cdk-lib/aws-codecommit/lib/repository.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as notifications from '../../aws-codestarnotifications';
55
import * as events from '../../aws-events';
66
import * as iam from '../../aws-iam';
77
import * as kms from '../../aws-kms';
8-
import { ArnFormat, IResource, Lazy, Resource, Stack } from '../../core';
8+
import { ArnFormat, IResource, Lazy, Resource, Stack, ValidationError } from '../../core';
99
import { addConstructMetadata, MethodMetadata } from '../../core/lib/metadata-resource';
1010

1111
/**
@@ -605,7 +605,7 @@ export class Repository extends RepositoryBase {
605605
}
606606

607607
if (this.triggers.find(prop => prop.name === name)) {
608-
throw new Error(`Unable to set repository trigger named ${name} because trigger names must be unique`);
608+
throw new ValidationError(`Unable to set repository trigger named ${name} because trigger names must be unique`, this);
609609
}
610610

611611
this.triggers.push({

0 commit comments

Comments
 (0)