Skip to content

Commit

Permalink
chore: enforce no-throw-literal (#32331)
Browse files Browse the repository at this point in the history
### Reason for this change

As part of #32324 we are enforcing stricter rules on thrown errors.

### Description of changes

Enforce the `no-throw-literal` eslint rule.
Fix the one instance that wasn't compliant yet.

### Description of how you validated changes

Manual testing. Only changed code is in supporting CLI tool.

### 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*
  • Loading branch information
mrgrain authored Nov 29, 2024
1 parent 77fbddf commit 0e79874
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tools/@aws-cdk/cdk-build-tools/config/eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ module.exports = {
'@cdklabs/no-invalid-path': [ 'error' ],
'@cdklabs/promiseall-no-unbounded-parallelism': [ 'error' ],

// Error handling
'no-throw-literal': [ 'error' ],

// Require use of the `import { foo } from 'bar';` form instead of `import foo = require('bar');`
'@typescript-eslint/no-require-imports': ['error'],
'@typescript-eslint/indent': ['error', 2],
Expand Down
2 changes: 1 addition & 1 deletion tools/@aws-cdk/spec2cdk/lib/util/patterned-name.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function parsePattern<A extends string>(pattern: string, fields: { [k in A]: unknown }): PatternedString<A> {
const placeholders = Object.keys(fields);
if (!placeholders.some((param) => pattern.includes(param))) {
throw `Error: --pattern must contain one of [${placeholders.join(', ')}]`;
throw new Error(`--pattern must contain one of [${placeholders.join(', ')}]`);
}

return (values: { [k in A]: string }) => {
Expand Down

0 comments on commit 0e79874

Please sign in to comment.