Skip to content

Commit b0302ca

Browse files
committed
Log if a database metadata file could not be found
This is a key cause of not being able to produce interpreted results, so logging it helps us debug a lack of interpreted results. Also make the database metadata check async
1 parent 513d763 commit b0302ca

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

extensions/ql-vscode/src/databases.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ export interface DatabaseItem {
227227
resolveSourceFile(file: string | undefined): vscode.Uri;
228228

229229
/**
230-
* Holds if the database item has a `.dbinfo` file.
230+
* Holds if the database item has a `.dbinfo` or `codeql-database.yml` file.
231231
*/
232-
hasDbInfo(): boolean;
232+
hasMetadataFile(): Promise<boolean>;
233233

234234
/**
235235
* Returns `sourceLocationPrefix` of exported database.
@@ -359,9 +359,11 @@ class DatabaseItemImpl implements DatabaseItem {
359359
/**
360360
* Holds if the database item refers to an exported snapshot
361361
*/
362-
public hasDbInfo(): boolean {
363-
return fs.existsSync(path.join(this.databaseUri.fsPath, '.dbinfo'))
364-
|| fs.existsSync(path.join(this.databaseUri.fsPath, 'codeql-database.yml'));;
362+
public async hasMetadataFile(): Promise<boolean> {
363+
return (await Promise.all([
364+
fs.pathExists(path.join(this.databaseUri.fsPath, '.dbinfo')),
365+
fs.pathExists(path.join(this.databaseUri.fsPath, 'codeql-database.yml'))
366+
])).some(x => x);
365367
}
366368

367369
/**

extensions/ql-vscode/src/queries.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ export class QueryInfo {
150150
/**
151151
* Holds if this query should produce interpreted results.
152152
*/
153-
hasInterpretedResults(): boolean {
154-
return this.dbItem.hasDbInfo();
153+
async hasInterpretedResults(): Promise<boolean> {
154+
const hasMetadataFile = await this.dbItem.hasMetadataFile();
155+
if (!hasMetadataFile) {
156+
logger.log("Cannot produce interpreted results since the database does not have a .dbinfo or codeql-database.yml file.");
157+
}
158+
return hasMetadataFile;
155159
}
156160

157161
async updateSortState(server: cli.CodeQLCliServer, resultSetName: string, sortState: SortState | undefined): Promise<void> {

0 commit comments

Comments
 (0)