Skip to content

Commit 676546d

Browse files
alexetaeisenberg
authored andcommitted
Adress review comments
1 parent a25db96 commit 676546d

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

extensions/ql-vscode/src/run-queries.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,7 @@ async function checkDbschemeCompatibility(
330330
}
331331
}
332332

333-
334333
function reportNoUpgradePath(query: QueryInfo) {
335-
logger.log(`Query ${query.program.queryPath} expects database scheme ${query.queryDbscheme}, but database has scheme ${query.program.dbschemePath}, and no upgrade path found`);
336334
throw new Error(`Query ${query.program.queryPath} expects database scheme ${query.queryDbscheme}, but the current database has a different scheme, and no database upgrades are available. The current database scheme may be newer than the CodeQL query libraries in your workspace. Please try using a newer version of the query libraries.`);
337335
}
338336

@@ -348,7 +346,7 @@ async function compileNonDestructiveUpgrade(
348346
): Promise<string> {
349347
const searchPath = helpers.getOnDiskWorkspaceFolders();
350348

351-
if (query.dbItem.contents === undefined || query.dbItem.contents.dbSchemeUri === undefined) {
349+
if (!query.dbItem?.contents?.dbSchemeUri) {
352350
throw new Error('Database is invalid, and cannot be upgraded.');
353351
}
354352
const { scripts, matchesTarget } = await qs.cliServer.resolveUpgrades(query.dbItem.contents.dbSchemeUri.fsPath, searchPath, query.queryDbscheme);
@@ -573,7 +571,8 @@ export async function compileAndRunQueryAgainstDatabase(
573571
throw e;
574572
}
575573
}
576-
if (errors.length == 0) {
574+
575+
if (errors.length === 0) {
577576
const result = await query.run(qs, upgradeQlo, progress, token);
578577
if (result.resultType !== messages.QueryResultType.SUCCESS) {
579578
const message = result.message || 'Failed to run query';
@@ -611,10 +610,7 @@ export async function compileAndRunQueryAgainstDatabase(
611610
if (quickEval && formattedMessages.length <= 3) {
612611
showAndLogErrorMessage('Quick evaluation compilation failed: \n' + formattedMessages.join('\n'));
613612
} else {
614-
showAndLogErrorMessage((quickEval ? 'Quick evaluation' : 'Query') +
615-
' compilation failed. Please make sure there are no errors in the query, the database is up to date,' +
616-
' and the query and database use the same target language. For more details on the error, go to View > Output,' +
617-
' and choose CodeQL Query Server from the dropdown.');
613+
showAndLogErrorMessage((quickEval ? 'Quick evaluation' : 'Query') + compilationFailedErrorTail);
618614
}
619615

620616
return createSyntheticResult(query, db, historyItemOptions, 'Query had compilation errors', messages.QueryResultType.OTHER_ERROR);
@@ -624,6 +620,10 @@ export async function compileAndRunQueryAgainstDatabase(
624620
}
625621
}
626622

623+
const compilationFailedErrorTail = ' compilation failed. Please make sure there are no errors in the query, the database is up to date,' +
624+
' and the query and database use the same target language. For more details on the error, go to View > Output,' +
625+
' and choose CodeQL Query Server from the dropdown.';
626+
627627
function createSyntheticResult(
628628
query: QueryInfo,
629629
db: DatabaseItem,

extensions/ql-vscode/src/upgrades.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as qsClient from './queryserver-client';
88
import { upgradesTmpDir } from './run-queries';
99
import * as tmp from 'tmp';
1010
import * as path from 'path';
11+
import * as semver from 'semver';
1112
import { getOnDiskWorkspaceFolders } from './helpers';
1213

1314
/**
@@ -27,7 +28,7 @@ const MAX_UPGRADE_MESSAGE_LINES = 10;
2728
export async function hasNondestructiveUpgradeCapabilities(qs: qsClient.QueryServerClient): Promise<boolean> {
2829
// TODO change to actual version when known
2930
// Note it is probably something 2.4.something
30-
return (await qs.cliServer.getVersion()).compare('2.3.2') >= 0;
31+
return semver.gte(await qs.cliServer.getVersion(), '2.3.2');
3132
}
3233

3334

@@ -66,7 +67,7 @@ async function compileDatabaseUpgrade(
6667
if (await hasNondestructiveUpgradeCapabilities(qs)) {
6768
return await compileDatabaseUpgradeSequence(qs, db, targetDbScheme, resolvedSequence, currentUpgradeTmp, progress, token);
6869
} else {
69-
if (db.contents === undefined || db.contents.dbSchemeUri === undefined) {
70+
if (!db.contents?.dbSchemeUri) {
7071
throw new Error('Database is invalid, and cannot be upgraded.');
7172
}
7273
// We have the upgrades we want but compileUpgrade
@@ -123,7 +124,7 @@ async function checkAndConfirmDatabaseUpgrade(
123124
dialogOptions.push(showLogItem);
124125
}
125126

126-
const message = `Should the database ${db} be upgraded?\n\n${messageLines.join('\n')}`;
127+
const message = `Should the database ${db.databaseUri.fsPath} be upgraded?\n\n${messageLines.join('\n')}`;
127128
const chosenItem = await vscode.window.showInformationMessage(message, { modal: true }, ...dialogOptions);
128129

129130
if (chosenItem === showLogItem) {
@@ -164,7 +165,7 @@ export async function upgradeDatabaseExplicit(
164165

165166
const searchPath: string[] = getOnDiskWorkspaceFolders();
166167

167-
if (db.contents === undefined || db.contents.dbSchemeUri === undefined) {
168+
if (!db?.contents?.dbSchemeUri) {
168169
throw new Error('Database is invalid, and cannot be upgraded.');
169170
}
170171
const upgradeInfo = await qs.cliServer.resolveUpgrades(

0 commit comments

Comments
 (0)