Skip to content

Commit 9f22cb7

Browse files
authored
fix(data-service): Ignore errors when getParameter for featureCompatVersion fails (#2551)
1 parent 0c43de3 commit 9f22cb7

File tree

2 files changed

+52
-35
lines changed

2 files changed

+52
-35
lines changed

packages/data-service/src/instance-detail-helper.spec.ts

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -229,48 +229,62 @@ describe('instance-detail-helper', function () {
229229
return client as MongoClient;
230230
}
231231

232-
it('should throw if buildInfo was not available', async function () {
233-
const client = createMongoClientMock();
234-
235-
try {
236-
await getInstance(client);
237-
} catch (e) {
238-
expect(e).to.be.instanceof(Error);
239-
return;
240-
}
232+
context('when errors returned from commands', function () {
233+
it('should throw if buildInfo was not available', async function () {
234+
const client = createMongoClientMock();
235+
236+
try {
237+
await getInstance(client);
238+
} catch (e) {
239+
expect(e).to.be.instanceof(Error);
240+
return;
241+
}
242+
243+
throw new Error("getInstance didn't throw");
244+
});
241245

242-
throw new Error("getInstance didn't throw");
243-
});
246+
it('should handle auth errors gracefully on any command except buildInfo', async function () {
247+
const client = createMongoClientMock({
248+
buildInfo: {},
249+
});
244250

245-
it('should handle auth errors gracefully on any command', async function () {
246-
const client = createMongoClientMock({
247-
buildInfo: {},
251+
await getInstance(client);
248252
});
249253

250-
await getInstance(client);
251-
});
254+
// eslint-disable-next-line mocha/no-setup-in-describe
255+
['connectionStatus', 'hostInfo', 'listDatabases', 'dbStats'].forEach(
256+
(commandName) => {
257+
it(`should throw if server returned an unexpected error on ${commandName} command`, async function () {
258+
const randomError = new Error('Whoops');
259+
260+
const client = createMongoClientMock({
261+
buildInfo: {},
262+
listDatabases: fixtures.LIST_DATABASES_NAME_ONLY,
263+
[commandName]: randomError,
264+
});
265+
266+
try {
267+
await getInstance(client);
268+
} catch (e) {
269+
expect(e).to.eq(randomError);
270+
return;
271+
}
252272

253-
it('should throw if server returned an unexpected error on any command', async function () {
254-
const randomError = new Error('Whoops');
273+
throw new Error("getInstance didn't throw");
274+
});
275+
}
276+
);
255277

256-
const client = createMongoClientMock({
257-
connectionStatus: randomError,
258-
getCmdLineOpts: randomError,
259-
hostInfo: randomError,
260-
listDatabases: randomError,
261-
getParameter: randomError,
262-
dbStats: randomError,
263-
buildInfo: {},
264-
});
278+
it('should ignore all errors returned from getParameter command', async function () {
279+
const randomError = new Error('Whoops');
265280

266-
try {
267-
await getInstance(client);
268-
} catch (e) {
269-
expect(e).to.eq(randomError);
270-
return;
271-
}
281+
const client = createMongoClientMock({
282+
buildInfo: {},
283+
getParameter: randomError,
284+
});
272285

273-
throw new Error("getInstance didn't throw");
286+
await getInstance(client);
287+
});
274288
});
275289

276290
it('should parse build info', async function () {

packages/data-service/src/instance-detail-helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,13 @@ export async function getInstance(
113113
runCommand(adminDb, { listDatabases: 1, nameOnly: true }).catch(
114114
ignoreNotAuthorized(null)
115115
),
116+
// This command is only here to get data for the logs and telemetry, if it
117+
// failed (e.g., not authorised or not supported) we should just ignore the
118+
// failure
116119
runCommand<{ featureCompatibilityVersion: { version: string } }>(adminDb, {
117120
getParameter: 1,
118121
featureCompatibilityVersion: 1,
119-
}).catch(ignoreNotAuthorized(null)),
122+
}).catch(() => null),
120123
]);
121124

122125
const databases = await fetchDatabases(

0 commit comments

Comments
 (0)