Skip to content

Commit 565e9fb

Browse files
aeisenbergadityasharad
authored andcommitted
Make error messages clearer for some common problems
1. Clicking on query history menu items when nothing is selected. Error message is clearer. It would be better to disable when nothing is selected, but waiting on microsoft/vscode#99767 to be released. 2. Trying to run query with a missing or invalid qlpack has better message. 3. Better hover text for "Open query". Co-authored-by: Aditya Sharad <6874315+adityasharad@users.noreply.github.com>
1 parent 034006f commit 565e9fb

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

extensions/ql-vscode/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- Fix bug when removing databases where sometimes the source folder would not be removed from the workspace or the database files would not be removed from the workspace storage location. [#692](https://github.com/github/vscode-codeql/pull/692)
77
- Query results with no string representation will now be displayed with placeholder text in query results. Previously, they were omitted. [#694](https://github.com/github/vscode-codeql/pull/694)
88
- Add a label for the language of a database in the databases view. This will only take effect for new databases created with the CodeQL CLI v2.4.1 or later. [#697](https://github.com/github/vscode-codeql/pull/697)
9+
- Add clearer error message when running a query using a missing or invalid qlpack. [#702](https://github.com/github/vscode-codeql/pull/702)
10+
- Add clearer error message when trying to run a command from the query history view if no item in the history is selected. [#702](https://github.com/github/vscode-codeql/pull/702)
911

1012
## 1.3.7 - 24 November 2020
1113

extensions/ql-vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
},
317317
{
318318
"command": "codeQLQueryHistory.openQuery",
319-
"title": "Open Query",
319+
"title": "Open the query that produced these results",
320320
"icon": {
321321
"light": "media/light/edit.svg",
322322
"dark": "media/dark/edit.svg"

extensions/ql-vscode/src/query-history.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class HistoryTreeDataProvider extends DisposableObject implements QueryHistoryDa
173173
*/
174174
const DOUBLE_CLICK_TIME = 500;
175175

176+
const NO_QUERY_SELECTED = 'No query selected. Select a query history item you have already run and try again.';
176177
export class QueryHistoryManager extends DisposableObject {
177178
treeDataProvider: HistoryTreeDataProvider;
178179
treeView: vscode.TreeView<CompletedQuery>;
@@ -311,6 +312,10 @@ export class QueryHistoryManager extends DisposableObject {
311312
return;
312313
}
313314

315+
if (!finalSingleItem) {
316+
throw new Error(NO_QUERY_SELECTED);
317+
}
318+
314319
const textDocument = await vscode.workspace.openTextDocument(
315320
vscode.Uri.file(finalSingleItem.query.program.queryPath)
316321
);
@@ -399,6 +404,11 @@ export class QueryHistoryManager extends DisposableObject {
399404
if (!this.assertSingleQuery(finalMultiSelect)) {
400405
return;
401406
}
407+
408+
if (!finalSingleItem) {
409+
throw new Error(NO_QUERY_SELECTED);
410+
}
411+
402412
this.treeDataProvider.setCurrentItem(finalSingleItem);
403413

404414
const now = new Date();
@@ -441,6 +451,10 @@ export class QueryHistoryManager extends DisposableObject {
441451
return;
442452
}
443453

454+
if (!singleItem) {
455+
throw new Error(NO_QUERY_SELECTED);
456+
}
457+
444458
const queryName = singleItem.queryName.endsWith('.ql')
445459
? singleItem.queryName
446460
: singleItem.queryName + '.ql';

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ async function promptUserToSaveChanges(document: TextDocument): Promise<boolean>
346346
else {
347347
const yesItem = { title: 'Yes', isCloseAffordance: false };
348348
const alwaysItem = { title: 'Always Save', isCloseAffordance: false };
349-
const noItem = { title: 'No (run anyway)', isCloseAffordance: false };
349+
const noItem = { title: 'No (run version on disk)', isCloseAffordance: false };
350350
const cancelItem = { title: 'Cancel', isCloseAffordance: true };
351351
const message = 'Query file has unsaved changes. Save now?';
352352
const chosenItem = await window.showInformationMessage(
@@ -479,6 +479,10 @@ export async function compileAndRunQueryAgainstDatabase(
479479
// Figure out the library path for the query.
480480
const packConfig = await cliServer.resolveLibraryPath(diskWorkspaceFolders, queryPath);
481481

482+
if (!packConfig.dbscheme) {
483+
throw new Error('Could not find a database scheme for this query. Please check that you have a valid qlpack.yml file for this query, which refers to a database scheme either in the `dbscheme` field or through one of its dependencies.');
484+
}
485+
482486
// Check whether the query has an entirely different schema from the
483487
// database. (Queries that merely need the database to be upgraded
484488
// won't trigger this check)

0 commit comments

Comments
 (0)