Skip to content

Commit 6c4181b

Browse files
authored
fix(core): Tag must have a value error is impossible to attribute to a specific tag (#35091)
### Issue # (if applicable) Not applicable ### Reason for this change Make it clearer as to what tag has invalid values - currently the process to identify said tag is not as clear as it could be. ### Description of changes Improve error message from `Tag must have a value` to `Tag '${key}' must have a value` ### Describe any new or updated permissions being added Not applicable ### Description of how you validated changes Test added ### 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 1da883e commit 6c4181b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/aws-cdk-lib/core/lib/tag-aspect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class Tag extends TagBase {
121121
constructor(key: string, value: string, props: TagProps = {}) {
122122
super(key, props);
123123
if (value === undefined) {
124-
throw new UnscopedValidationError('Tag must have a value');
124+
throw new UnscopedValidationError(`Tag '${key}' must have a value`);
125125
}
126126
this.value = value;
127127
}

packages/aws-cdk-lib/core/test/tag-aspect.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ITaggable,
1414
ITaggableV2,
1515
AspectPriority,
16+
UnscopedValidationError,
1617
} from '../lib';
1718
import { synthesize } from '../lib/private/synthesis';
1819

@@ -331,4 +332,14 @@ describe('tag aspect', () => {
331332
}).toThrow();
332333
});
333334
});
335+
336+
test('if tag value is undefined, it raises with appropriate content', () => {
337+
expect(() => {
338+
new Tag('test-key', undefined as any);
339+
}).toThrow(UnscopedValidationError);
340+
341+
expect(() => {
342+
new Tag('test-key', undefined as any);
343+
}).toThrow("Tag 'test-key' must have a value");
344+
});
334345
});

0 commit comments

Comments
 (0)