Skip to content

Commit b470e41

Browse files
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 370dbcb commit b470e41

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
@@ -304,7 +304,7 @@
304304
},
305305
{
306306
"command": "codeQLQueryHistory.openQuery",
307-
"title": "Open Query",
307+
"title": "Open the query that produced these results",
308308
"icon": {
309309
"light": "media/light/edit.svg",
310310
"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
@@ -172,6 +172,7 @@ class HistoryTreeDataProvider extends DisposableObject implements QueryHistoryDa
172172
*/
173173
const DOUBLE_CLICK_TIME = 500;
174174

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

314+
if (!finalSingleItem) {
315+
throw new Error(NO_QUERY_SELECTED);
316+
}
317+
313318
const textDocument = await vscode.workspace.openTextDocument(
314319
vscode.Uri.file(finalSingleItem.query.program.queryPath)
315320
);
@@ -398,6 +403,11 @@ export class QueryHistoryManager extends DisposableObject {
398403
if (!this.assertSingleQuery(finalMultiSelect)) {
399404
return;
400405
}
406+
407+
if (!finalSingleItem) {
408+
throw new Error(NO_QUERY_SELECTED);
409+
}
410+
401411
this.treeDataProvider.setCurrentItem(finalSingleItem);
402412

403413
const now = new Date();
@@ -440,6 +450,10 @@ export class QueryHistoryManager extends DisposableObject {
440450
return;
441451
}
442452

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

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

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

481+
if (!packConfig.dbscheme) {
482+
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.');
483+
}
484+
481485
// Check whether the query has an entirely different schema from the
482486
// database. (Queries that merely need the database to be upgraded
483487
// won't trigger this check)

0 commit comments

Comments
 (0)