From 0e79874623ecf34df998dd3c85f8de3fbe51b7ee Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Fri, 29 Nov 2024 14:02:39 +0000 Subject: [PATCH] chore: enforce no-throw-literal (#32331) ### 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* --- tools/@aws-cdk/cdk-build-tools/config/eslintrc.js | 3 +++ tools/@aws-cdk/spec2cdk/lib/util/patterned-name.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/@aws-cdk/cdk-build-tools/config/eslintrc.js b/tools/@aws-cdk/cdk-build-tools/config/eslintrc.js index 0273756166e97..40f98b3e4bc84 100644 --- a/tools/@aws-cdk/cdk-build-tools/config/eslintrc.js +++ b/tools/@aws-cdk/cdk-build-tools/config/eslintrc.js @@ -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], diff --git a/tools/@aws-cdk/spec2cdk/lib/util/patterned-name.ts b/tools/@aws-cdk/spec2cdk/lib/util/patterned-name.ts index e1bb95c7bf189..88e4e1d708c83 100644 --- a/tools/@aws-cdk/spec2cdk/lib/util/patterned-name.ts +++ b/tools/@aws-cdk/spec2cdk/lib/util/patterned-name.ts @@ -1,7 +1,7 @@ export function parsePattern(pattern: string, fields: { [k in A]: unknown }): PatternedString { 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 }) => {