diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index a6744e4e0356a..f7f58b7f071f7 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -18,7 +18,6 @@ baseConfig.rules['@cdklabs/no-throw-default-error'] = ['error']; // not yet supported const noThrowDefaultErrorNotYetSupported = [ 'core', - 'region-info', ]; baseConfig.overrides.push({ files: [ diff --git a/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts b/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts index a76ce0a3221f7..3c15b72879515 100644 --- a/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts +++ b/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts @@ -18,9 +18,9 @@ import { import { AWS_CDK_METADATA } from './metadata'; import { AWS_REGIONS, - before, RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN, RULE_CLASSIC_PARTITION_BECOMES_OPT_IN, + AWS_REGIONS_AND_RULES, } from '../lib/aws-entities'; export async function main(): Promise { @@ -169,10 +169,24 @@ function checkRegionsSubMap(map: Record we have to assume no. + */ +function before(region: string, ruleOrRegion: string | symbol) { + const ruleIx = AWS_REGIONS_AND_RULES.indexOf(ruleOrRegion); + if (ruleIx === -1) { + throw new Error(`Unknown rule: ${String(ruleOrRegion)}`); + } + const regionIx = AWS_REGIONS_AND_RULES.indexOf(region); + return regionIx === -1 ? false : regionIx < ruleIx; +} + main().catch(e => { // eslint-disable-next-line no-console console.error(e); diff --git a/packages/aws-cdk-lib/region-info/lib/aws-entities.ts b/packages/aws-cdk-lib/region-info/lib/aws-entities.ts index d5abbb2a28d48..4eef2a9bbdce2 100644 --- a/packages/aws-cdk-lib/region-info/lib/aws-entities.ts +++ b/packages/aws-cdk-lib/region-info/lib/aws-entities.ts @@ -80,33 +80,6 @@ export const AWS_REGIONS = AWS_REGIONS_AND_RULES .filter((x) => typeof x === 'string') .sort() as readonly string[]; -/** - * Whether or not a region predates a given rule (or region). - * - * Unknown region => we have to assume no. - */ -export function before(region: string, ruleOrRegion: string | symbol) { - const ruleIx = AWS_REGIONS_AND_RULES.indexOf(ruleOrRegion); - if (ruleIx === -1) { - throw new Error(`Unknown rule: ${String(ruleOrRegion)}`); - } - const regionIx = AWS_REGIONS_AND_RULES.indexOf(region); - return regionIx === -1 ? false : regionIx < ruleIx; -} - -/** - * Return all regions before a given rule was introduced (or region) - */ -export function regionsBefore(ruleOrRegion: string | symbol): string[] { - const ruleIx = AWS_REGIONS_AND_RULES.indexOf(ruleOrRegion); - if (ruleIx === -1) { - throw new Error(`Unknown rule: ${String(ruleOrRegion)}`); - } - return AWS_REGIONS_AND_RULES.slice(0, ruleIx) - .filter((entry) => typeof entry === 'string') - .sort() as string[]; -} - export interface Region { readonly partition: string; readonly domainSuffix: string } const PARTITION_MAP: {readonly [region: string]: Region } = { diff --git a/packages/aws-cdk-lib/region-info/lib/fact.ts b/packages/aws-cdk-lib/region-info/lib/fact.ts index 9c0d68ab56f4d..73343a846da52 100644 --- a/packages/aws-cdk-lib/region-info/lib/fact.ts +++ b/packages/aws-cdk-lib/region-info/lib/fact.ts @@ -1,4 +1,5 @@ import { AWS_REGIONS } from './aws-entities'; +import { UnscopedValidationError } from '../../core/lib/errors'; /** * A database of regional information. @@ -56,7 +57,7 @@ export class Fact { const foundFact = this.find(region, name); if (!foundFact) { - throw new Error(`No fact ${name} could be found for region: ${region} and name: ${name}.`); + throw new UnscopedValidationError(`No fact ${name} could be found for region: ${region} and name: ${name}.`); } return foundFact; @@ -71,7 +72,7 @@ export class Fact { public static register(fact: IFact, allowReplacing = false): void { const regionFacts = this.database[fact.region] || (this.database[fact.region] = {}); if (fact.name in regionFacts && regionFacts[fact.name] !== fact.value && !allowReplacing) { - throw new Error(`Region ${fact.region} already has a fact ${fact.name}, with value ${regionFacts[fact.name]}`); + throw new UnscopedValidationError(`Region ${fact.region} already has a fact ${fact.name}, with value ${regionFacts[fact.name]}`); } if (fact.value !== undefined) { regionFacts[fact.name] = fact.value; @@ -88,7 +89,7 @@ export class Fact { public static unregister(region: string, name: string, value?: string): void { const regionFacts = this.database[region] || {}; if (name in regionFacts && value && regionFacts[name] !== value) { - throw new Error(`Attempted to remove ${name} from ${region} with value ${value}, but the fact's value is ${regionFacts[name]}`); + throw new UnscopedValidationError(`Attempted to remove ${name} from ${region} with value ${value}, but the fact's value is ${regionFacts[name]}`); } delete regionFacts[name]; } @@ -96,7 +97,7 @@ export class Fact { private static readonly database: { [region: string]: { [name: string]: string } } = {}; private constructor() { - throw new Error('Use the static methods of Fact instead!'); + throw new UnscopedValidationError('Use the static methods of Fact instead!'); } }