Skip to content

Commit 4dea1e1

Browse files
fix(regions): don't crash the Resources view on an un-tabled region
getRegionLongName threw for any region missing from its hardcoded table, so a single such region in the running emulator's metamodel (e.g. cn-north-1) aborted the whole "All Resources" view. It now degrades to the region code for unknown regions, and the China partition (cn-north-1, cn-northwest-1) is added to the table. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d2effe9 commit 4dea1e1

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

src/platforms/aws/models/regionModel.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { InternalError } from "../../../utils/errors.ts";
2-
31
/*
42
* To save an API call (or many), we hard-code these region names.
53
* AWS will add more over time and we can update this list as needed.
@@ -22,6 +20,8 @@ const REGION_NAMES: { [key: string]: string } = {
2220
"ap-southeast-7": "Asia Pacific (Thailand)",
2321
"ca-central-1": "Canada (Central)",
2422
"ca-west-1": "Canada West (Calgary)",
23+
"cn-north-1": "China (Beijing)",
24+
"cn-northwest-1": "China (Ningxia)",
2525
"eu-central-1": "Europe (Frankfurt)",
2626
"eu-central-2": "Europe (Zurich)",
2727
"eu-north-1": "Europe (Stockholm)",
@@ -46,15 +46,14 @@ const REGION_NAMES: { [key: string]: string } = {
4646
/**
4747
* Get the long name of an AWS region.
4848
* @param region The short name of the region (e.g., "us-east-1").
49-
* @returns The long name of the region (e.g., "US East (N. Virginia)").
49+
* @returns The long name of the region (e.g., "US East (N. Virginia)"), or the
50+
* region code itself when it is not in the table. The running emulator can
51+
* report any region in its metamodel (including partitions we have not
52+
* enumerated), so an unknown region must degrade to its code rather than throw
53+
* and break the whole "All Resources" view.
5054
*/
5155
export function getRegionLongName(region: string): string {
52-
if (!REGION_NAMES[region]) {
53-
throw new InternalError(
54-
`Unknown region: ${region}. The region information might need to be updated.`,
55-
);
56-
}
57-
return REGION_NAMES[region];
56+
return REGION_NAMES[region] ?? region;
5857
}
5958

6059
/**
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import assert from "node:assert";
2+
3+
import {
4+
getAllRegionCodes,
5+
getRegionLongName,
6+
} from "../../platforms/aws/models/regionModel.ts";
7+
8+
/**
9+
* Region lookups back both the cloud-profile add-region picker and the region
10+
* labels shown in the Resources view. The latter renders whatever region the
11+
* running emulator reports in its metamodel, so an unknown region must degrade
12+
* to its code rather than throw and break the whole "All Resources" view.
13+
*/
14+
suite("regionModel", () => {
15+
test("returns the long name for a known region", () => {
16+
assert.strictEqual(getRegionLongName("us-east-1"), "US East (N. Virginia)");
17+
assert.strictEqual(getRegionLongName("cn-north-1"), "China (Beijing)");
18+
});
19+
20+
test("falls back to the region code for an unknown region", () => {
21+
assert.strictEqual(getRegionLongName("xx-unknown-9"), "xx-unknown-9");
22+
});
23+
24+
test("exposes the China partition regions in the region list", () => {
25+
const codes = getAllRegionCodes();
26+
assert.ok(codes.includes("cn-north-1"));
27+
assert.ok(codes.includes("cn-northwest-1"));
28+
});
29+
});

0 commit comments

Comments
 (0)