Skip to content

Commit ee33e31

Browse files
committed
Fix mixed undefined/Promise values in Promise.all in updates.ts
This commit fixes incorrect usage of Promise.all() where the mapped array could contain undefined values mixed with Promises, causing ESLint errors. Problem: The downloadDatabaseUpdateFromGitHub function was passing an array to Promise.all() where map callbacks could return either: - undefined (when no update is found for a database) - A Promise<void> (from the withProgress call) ESLint rule '@typescript-eslint/await-thenable' detected this error at line 172: 'Unexpected iterable of non-Promise (non-"Thenable") values passed to promise aggregator' The code pattern was: await Promise.all( selectedDatabases.map((database) => { const update = updates.find(...); return; // ❌ returns undefined } return withProgress(...); // ✓ returns Promise }) ); This creates an array like [Promise, undefined, Promise, undefined] which violates Promise.all()'s type contract expecting all Promises. Solution: 1. Change early return from 'return;' to 'return undefined;' for explicit clarity 2. Filter out undefined values before passing to Promise.all() using a type guard: .filter((p): p is Promise<void> => p !== undefined) This ensures Promise.all() receives only actual Promise objects while maintaining the same runtime behavior (skipping databases without updates). File modified: - extensions/ql-vscode/src/databases/github-databases/updates.ts
1 parent 8793d0b commit ee33e31

File tree

1 file changed

+40
-38
lines changed
  • extensions/ql-vscode/src/databases/github-databases

1 file changed

+40
-38
lines changed

extensions/ql-vscode/src/databases/github-databases/updates.ts

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -169,46 +169,48 @@ export async function downloadDatabaseUpdateFromGitHub(
169169
}
170170

171171
await Promise.all(
172-
selectedDatabases.map((database) => {
173-
const update = updates.find((update) => update.database === database);
174-
if (!update) {
175-
return;
176-
}
172+
selectedDatabases
173+
.map((database) => {
174+
const update = updates.find((update) => update.database === database);
175+
if (!update) {
176+
return undefined;
177+
}
177178

178-
return withProgress(
179-
async (progress) => {
180-
const newDatabase =
181-
await databaseFetcher.downloadGitHubDatabaseFromUrl(
182-
database.url,
183-
database.id,
184-
database.created_at,
185-
database.commit_oid ?? null,
186-
owner,
187-
repo,
188-
octokit,
189-
progress,
190-
databaseManager.currentDatabaseItem === update.databaseItem,
191-
update.databaseItem.hasSourceArchiveInExplorer(),
179+
return withProgress(
180+
async (progress) => {
181+
const newDatabase =
182+
await databaseFetcher.downloadGitHubDatabaseFromUrl(
183+
database.url,
184+
database.id,
185+
database.created_at,
186+
database.commit_oid ?? null,
187+
owner,
188+
repo,
189+
octokit,
190+
progress,
191+
databaseManager.currentDatabaseItem === update.databaseItem,
192+
update.databaseItem.hasSourceArchiveInExplorer(),
193+
);
194+
if (newDatabase === undefined) {
195+
return;
196+
}
197+
198+
await databaseManager.removeDatabaseItem(update.databaseItem);
199+
200+
await commandManager.execute("codeQLDatabases.focus");
201+
void window.showInformationMessage(
202+
`Updated ${getLanguageDisplayName(
203+
database.language,
204+
)} database from GitHub.`,
192205
);
193-
if (newDatabase === undefined) {
194-
return;
195-
}
196-
197-
await databaseManager.removeDatabaseItem(update.databaseItem);
198-
199-
await commandManager.execute("codeQLDatabases.focus");
200-
void window.showInformationMessage(
201-
`Updated ${getLanguageDisplayName(
206+
},
207+
{
208+
title: `Updating ${getLanguageDisplayName(
202209
database.language,
203-
)} database from GitHub.`,
204-
);
205-
},
206-
{
207-
title: `Updating ${getLanguageDisplayName(
208-
database.language,
209-
)} database from GitHub`,
210-
},
211-
);
212-
}),
210+
)} database from GitHub`,
211+
},
212+
);
213+
})
214+
.filter((p): p is Promise<void> => p !== undefined),
213215
);
214216
}

0 commit comments

Comments
 (0)