You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(iam): throw ValidationErrors instead of untyped errors (#34579)
### Issue
Relates to #32569
### Reason for this change
untyped Errors are not recommended
### Description of changes
`ValidationError`s 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*
thrownewError(`Cannot use a ManagedPolicy '${this._managedPolicy.node.path}' as the 'Principal' or 'NotPrincipal' in an IAM Policy`);
351
+
thrownewUnscopedValidationError(`Cannot use a ManagedPolicy '${this._managedPolicy.node.path}' as the 'Principal' or 'NotPrincipal' in an IAM Policy`);
thrownewError(`Action '${action}' is invalid. An action string consists of a service namespace, a colon, and the name of an action. Action names can include wildcards.`);
240
+
thrownewUnscopedValidationError(`Action '${action}' is invalid. An action string consists of a service namespace, a colon, and the name of an action. Action names can include wildcards.`);
thrownewError(`All principals in a PolicyStatement must have the same Conditions (got '${this.principalConditionsJson}' and '${theseConditions}'). Use multiple statements instead.`);
521
+
thrownewUnscopedValidationError(`All principals in a PolicyStatement must have the same Conditions (got '${this.principalConditionsJson}' and '${theseConditions}'). Use multiple statements instead.`);
521
522
}
522
523
}
523
524
this.addConditions(conditions);
@@ -676,7 +677,7 @@ export class PolicyStatement {
676
677
*/
677
678
privateassertNotFrozen(method: string){
678
679
if(this._frozen){
679
-
thrownewError(`${method}: freeze() has been called on this PolicyStatement previously, so it can no longer be modified`);
680
+
thrownewUnscopedValidationError(`${method}: freeze() has been called on this PolicyStatement previously, so it can no longer be modified`);
680
681
}
681
682
}
682
683
}
@@ -810,7 +811,7 @@ class JsonPrincipal extends PrincipalBase {
810
811
json={[LITERAL_STRING_KEY]: [json]};
811
812
}
812
813
if(typeof(json)!=='object'){
813
-
thrownewError(`JSON IAM principal should be an object, got ${JSON.stringify(json)}`);
814
+
thrownewUnscopedValidationError(`JSON IAM principal should be an object, got ${JSON.stringify(json)}`);
814
815
}
815
816
816
817
this.policyFragment={
@@ -853,7 +854,7 @@ export function deriveEstimateSizeOptions(scope: IConstruct): EstimateSizeOption
thrownewError(`Cannot merge principals ${JSON.stringify(target)} and ${JSON.stringify(source)}; if one uses a literal principal string the other one must be empty`);
82
+
thrownewUnscopedValidationError(`Cannot merge principals ${JSON.stringify(target)} and ${JSON.stringify(source)}; if one uses a literal principal string the other one must be empty`);
0 commit comments