Skip to content

Commit bb658a0

Browse files
authored
fix(build): more resilient S3 handling for JSON feed MONGOSH-1242 (#1570)
Account for `NoSuchKey` errors being thrown when downloading files from AWS.
1 parent 4c8eede commit bb658a0

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

packages/build/src/download-center/config.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ export async function createAndPublishDownloadCenterConfig(
4545
accessKeyId: awsAccessKeyId,
4646
secretAccessKey: awsSecretAccessKey,
4747
});
48-
const existingDownloadCenterConfig = await dlcenter.downloadConfig(
49-
CONFIGURATION_KEY
50-
);
48+
let existingDownloadCenterConfig: DownloadCenterConfig | undefined;
49+
try {
50+
existingDownloadCenterConfig = await dlcenter.downloadConfig(
51+
CONFIGURATION_KEY
52+
);
53+
} catch (err: any) {
54+
console.warn('Failed to get existing download center config', err);
55+
if (err?.code !== 'NoSuchKey') throw err;
56+
}
5157

5258
const getVersionConfig = () =>
5359
createVersionConfig(packageInformation, publicArtifactBaseUrl);
@@ -59,7 +65,7 @@ export async function createAndPublishDownloadCenterConfig(
5965
: createDownloadCenterConfig(getVersionConfig);
6066

6167
console.warn('Created download center config:');
62-
//console.dir(config, { depth: Infinity });
68+
console.dir(config, { depth: Infinity });
6369

6470
validateConfigSchema(config);
6571

@@ -69,13 +75,20 @@ export async function createAndPublishDownloadCenterConfig(
6975
secretAccessKey: awsSecretAccessKey,
7076
});
7177
const jsonFeedArtifactkey = `${ARTIFACTS_FOLDER}/mongosh.json`;
72-
const existingJsonFeedText = await dlcenterArtifacts.downloadAsset(
73-
jsonFeedArtifactkey
74-
);
75-
const existingJsonFeed = existingJsonFeedText
78+
let existingJsonFeedText;
79+
try {
80+
existingJsonFeedText = await dlcenterArtifacts.downloadAsset(
81+
jsonFeedArtifactkey
82+
);
83+
} catch (err: any) {
84+
console.warn('Failed to get existing JSON feed text', err);
85+
if (err?.code !== 'NoSuchKey') throw err;
86+
}
87+
88+
const existingJsonFeed: JsonFeed | undefined = existingJsonFeedText
7689
? JSON.parse(existingJsonFeedText.toString())
7790
: undefined;
78-
const injectedJsonFeed = injectedJsonFeedFile
91+
const injectedJsonFeed: JsonFeed | undefined = injectedJsonFeedFile
7992
? JSON.parse(await fs.readFile(injectedJsonFeedFile, 'utf8'))
8093
: undefined;
8194
const currentJsonFeedEntry = await createJsonFeedEntry(
@@ -86,7 +99,7 @@ export async function createAndPublishDownloadCenterConfig(
8699
versions: [currentJsonFeedEntry],
87100
};
88101
console.warn('Adding new JSON feed entry:');
89-
//console.dir(currentJsonFeedEntry, { depth: Infinity });
102+
console.dir(currentJsonFeedEntry, { depth: Infinity });
90103

91104
const newJsonFeed = mergeFeeds(
92105
existingJsonFeed,
@@ -227,7 +240,7 @@ export async function createJsonFeedEntry(
227240
};
228241
}
229242

230-
function mergeFeeds(...args: JsonFeed[]): JsonFeed {
243+
function mergeFeeds(...args: (JsonFeed | undefined)[]): JsonFeed {
231244
const newFeed: JsonFeed = {
232245
versions: [],
233246
};

packages/build/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import type { Config, PackageVariant } from './config';
1010
export { getArtifactUrl, downloadMongoDb };
1111

1212
if (require.main === module) {
13+
Error.stackTraceLimit = 200;
14+
1315
(async () => {
1416
const command = process.argv[2];
1517
if (

0 commit comments

Comments
 (0)