Skip to content

Commit d44a76a

Browse files
committed
{ enableUtf8Validation: false } on each runCommand rather so we can argue about them one by one
1 parent f49a8a1 commit d44a76a

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

packages/data-service/src/data-service.ts

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,11 @@ class DataServiceImpl extends WithLogContext implements DataService {
11681168
@op(mongoLogId(1_001_000_031))
11691169
async killOp(id: number, comment?: string): Promise<Document> {
11701170
const db = this._database('admin', 'META');
1171-
return runCommand(db, { killOp: 1, id, comment });
1171+
return runCommand(
1172+
db,
1173+
{ killOp: 1, id, comment },
1174+
{ enableUtf8Validation: false }
1175+
);
11721176
}
11731177

11741178
isWritable(): boolean {
@@ -1186,10 +1190,14 @@ class DataServiceImpl extends WithLogContext implements DataService {
11861190
@op(mongoLogId(1_001_000_100))
11871191
private async _connectionStatus(): Promise<ConnectionStatusWithPrivileges> {
11881192
const adminDb = this._database('admin', 'META');
1189-
return await runCommand(adminDb, {
1190-
connectionStatus: 1,
1191-
showPrivileges: true,
1192-
});
1193+
return await runCommand(
1194+
adminDb,
1195+
{
1196+
connectionStatus: 1,
1197+
showPrivileges: true,
1198+
},
1199+
{ enableUtf8Validation: false }
1200+
);
11931201
}
11941202

11951203
private async _getPrivilegesOrFallback(
@@ -1229,7 +1237,7 @@ class DataServiceImpl extends WithLogContext implements DataService {
12291237
try {
12301238
const cursor = this._database(databaseName, 'CRUD').listCollections(
12311239
filter,
1232-
{ nameOnly, enableUtf8Validation: false }
1240+
{ nameOnly }
12331241
);
12341242
// Iterate instead of using .toArray() so we can emit
12351243
// collection info update events as they come in.
@@ -1344,12 +1352,16 @@ class DataServiceImpl extends WithLogContext implements DataService {
13441352

13451353
const listDatabases = async () => {
13461354
try {
1347-
const { databases } = await runCommand(adminDb, {
1348-
listDatabases: 1,
1349-
nameOnly,
1350-
} as {
1351-
listDatabases: 1;
1352-
});
1355+
const { databases } = await runCommand(
1356+
adminDb,
1357+
{
1358+
listDatabases: 1,
1359+
nameOnly,
1360+
} as {
1361+
listDatabases: 1;
1362+
},
1363+
{ enableUtf8Validation: false }
1364+
);
13531365
return databases;
13541366
} catch (err) {
13551367
// Currently Compass should not fail if listDatabase failed for any
@@ -2115,15 +2127,23 @@ class DataServiceImpl extends WithLogContext implements DataService {
21152127
})
21162128
async serverStatus(): Promise<Document> {
21172129
const admin = this._database('admin', 'META');
2118-
return await runCommand(admin, { serverStatus: 1 });
2130+
return await runCommand(
2131+
admin,
2132+
{ serverStatus: 1 },
2133+
{ enableUtf8Validation: false }
2134+
);
21192135
}
21202136

21212137
@op(mongoLogId(1_001_000_062), (_, result) => {
21222138
return result ? { result } : undefined;
21232139
})
21242140
async top(): Promise<{ totals: Record<string, unknown> }> {
21252141
const adminDb = this._database('admin', 'META');
2126-
return await runCommand(adminDb, { top: 1 });
2142+
return await runCommand(
2143+
adminDb,
2144+
{ top: 1 },
2145+
{ enableUtf8Validation: false }
2146+
);
21272147
}
21282148

21292149
@op(
@@ -2460,7 +2480,11 @@ class DataServiceImpl extends WithLogContext implements DataService {
24602480
name: string
24612481
): Promise<ReturnType<typeof adaptDatabaseInfo> & { name: string }> {
24622482
const db = this._database(name, 'META');
2463-
const stats = await runCommand(db, { dbStats: 1 });
2483+
const stats = await runCommand(
2484+
db,
2485+
{ dbStats: 1 },
2486+
{ enableUtf8Validation: false }
2487+
);
24642488
const normalized = adaptDatabaseInfo(stats);
24652489
return { name, ...normalized };
24662490
}

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,34 @@ export async function getInstance(
121121
atlasVersionResult,
122122
isLocalAtlas,
123123
] = await Promise.all([
124-
runCommand(adminDb, { connectionStatus: 1, showPrivileges: true }).catch(
125-
ignoreNotAuthorized(null)
124+
runCommand(
125+
adminDb,
126+
{ connectionStatus: 1, showPrivileges: true },
127+
{ enableUtf8Validation: false }
128+
).catch(ignoreNotAuthorized(null)),
129+
runCommand(adminDb, { hostInfo: 1 }, { enableUtf8Validation: false }).catch(
130+
ignoreNotAuthorized({})
126131
),
127-
runCommand(adminDb, { hostInfo: 1 }).catch(ignoreNotAuthorized({})),
128132
// This command should always pass, if it throws, somethings is really off.
129133
// This is why it's the only one where we are not ignoring any types of
130134
// errors
131-
runCommand(adminDb, { buildInfo: 1 }),
135+
runCommand(adminDb, { buildInfo: 1 }, { enableUtf8Validation: false }),
132136
// This command is only here to get data for the logs and telemetry, if it
133137
// failed (e.g., not authorised or not supported) we should just ignore the
134138
// failure
135-
runCommand<{ featureCompatibilityVersion: { version: string } }>(adminDb, {
136-
getParameter: 1,
137-
featureCompatibilityVersion: 1,
138-
}).catch(() => null),
139-
runCommand(adminDb, { atlasVersion: 1 }).catch(() => {
139+
runCommand<{ featureCompatibilityVersion: { version: string } }>(
140+
adminDb,
141+
{
142+
getParameter: 1,
143+
featureCompatibilityVersion: 1,
144+
},
145+
{ enableUtf8Validation: false }
146+
).catch(() => null),
147+
runCommand(
148+
adminDb,
149+
{ atlasVersion: 1 },
150+
{ enableUtf8Validation: false }
151+
).catch(() => {
140152
return { atlasVersion: '', gitVersion: '' };
141153
}),
142154
checkIsLocalAtlas(

packages/data-service/src/run-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export const runCommand: RunCommand = (
334334

335335
return db.command(
336336
{ ...spec },
337-
{ readPreference, enableUtf8Validation: false, ...options }
337+
{ readPreference, ...options }
338338
// It's pretty hard to convince TypeScript that we are doing the right thing
339339
// here due to how vague the driver types are hence the `any` assertion
340340
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)