Adress review comments

This commit is contained in:
alexet
2020-12-07 17:44:56 +00:00
committed by Andrew Eisenberg
parent a25db9616f
commit 676546d32b
2 changed files with 13 additions and 12 deletions

View File

@@ -330,9 +330,7 @@ async function checkDbschemeCompatibility(
}
}
function reportNoUpgradePath(query: QueryInfo) {
logger.log(`Query ${query.program.queryPath} expects database scheme ${query.queryDbscheme}, but database has scheme ${query.program.dbschemePath}, and no upgrade path found`);
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.`);
}
@@ -348,7 +346,7 @@ async function compileNonDestructiveUpgrade(
): Promise<string> {
const searchPath = helpers.getOnDiskWorkspaceFolders();
if (query.dbItem.contents === undefined || query.dbItem.contents.dbSchemeUri === undefined) {
if (!query.dbItem?.contents?.dbSchemeUri) {
throw new Error('Database is invalid, and cannot be upgraded.');
}
const { scripts, matchesTarget } = await qs.cliServer.resolveUpgrades(query.dbItem.contents.dbSchemeUri.fsPath, searchPath, query.queryDbscheme);
@@ -573,7 +571,8 @@ export async function compileAndRunQueryAgainstDatabase(
throw e;
}
}
if (errors.length == 0) {
if (errors.length === 0) {
const result = await query.run(qs, upgradeQlo, progress, token);
if (result.resultType !== messages.QueryResultType.SUCCESS) {
const message = result.message || 'Failed to run query';
@@ -611,10 +610,7 @@ export async function compileAndRunQueryAgainstDatabase(
if (quickEval && formattedMessages.length <= 3) {
showAndLogErrorMessage('Quick evaluation compilation failed: \n' + formattedMessages.join('\n'));
} else {
showAndLogErrorMessage((quickEval ? 'Quick evaluation' : 'Query') +
' compilation failed. Please make sure there are no errors in the query, the database is up to date,' +
' and the query and database use the same target language. For more details on the error, go to View > Output,' +
' and choose CodeQL Query Server from the dropdown.');
showAndLogErrorMessage((quickEval ? 'Quick evaluation' : 'Query') + compilationFailedErrorTail);
}
return createSyntheticResult(query, db, historyItemOptions, 'Query had compilation errors', messages.QueryResultType.OTHER_ERROR);
@@ -624,6 +620,10 @@ export async function compileAndRunQueryAgainstDatabase(
}
}
const compilationFailedErrorTail = ' compilation failed. Please make sure there are no errors in the query, the database is up to date,' +
' and the query and database use the same target language. For more details on the error, go to View > Output,' +
' and choose CodeQL Query Server from the dropdown.';
function createSyntheticResult(
query: QueryInfo,
db: DatabaseItem,

View File

@@ -8,6 +8,7 @@ import * as qsClient from './queryserver-client';
import { upgradesTmpDir } from './run-queries';
import * as tmp from 'tmp';
import * as path from 'path';
import * as semver from 'semver';
import { getOnDiskWorkspaceFolders } from './helpers';
/**
@@ -27,7 +28,7 @@ const MAX_UPGRADE_MESSAGE_LINES = 10;
export async function hasNondestructiveUpgradeCapabilities(qs: qsClient.QueryServerClient): Promise<boolean> {
// TODO change to actual version when known
// Note it is probably something 2.4.something
return (await qs.cliServer.getVersion()).compare('2.3.2') >= 0;
return semver.gte(await qs.cliServer.getVersion(), '2.3.2');
}
@@ -66,7 +67,7 @@ async function compileDatabaseUpgrade(
if (await hasNondestructiveUpgradeCapabilities(qs)) {
return await compileDatabaseUpgradeSequence(qs, db, targetDbScheme, resolvedSequence, currentUpgradeTmp, progress, token);
} else {
if (db.contents === undefined || db.contents.dbSchemeUri === undefined) {
if (!db.contents?.dbSchemeUri) {
throw new Error('Database is invalid, and cannot be upgraded.');
}
// We have the upgrades we want but compileUpgrade
@@ -123,7 +124,7 @@ async function checkAndConfirmDatabaseUpgrade(
dialogOptions.push(showLogItem);
}
const message = `Should the database ${db} be upgraded?\n\n${messageLines.join('\n')}`;
const message = `Should the database ${db.databaseUri.fsPath} be upgraded?\n\n${messageLines.join('\n')}`;
const chosenItem = await vscode.window.showInformationMessage(message, { modal: true }, ...dialogOptions);
if (chosenItem === showLogItem) {
@@ -164,7 +165,7 @@ export async function upgradeDatabaseExplicit(
const searchPath: string[] = getOnDiskWorkspaceFolders();
if (db.contents === undefined || db.contents.dbSchemeUri === undefined) {
if (!db?.contents?.dbSchemeUri) {
throw new Error('Database is invalid, and cannot be upgraded.');
}
const upgradeInfo = await qs.cliServer.resolveUpgrades(