Skip to content

Commit 69a4cac

Browse files
committed
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".
1 parent 370dbcb commit 69a4cac

4 files changed

Lines changed: 21 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 command from the query history view and no item is history 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ export class QueryHistoryManager extends DisposableObject {
310310
return;
311311
}
312312

313+
if (!finalSingleItem) {
314+
throw new Error('No query selected. Select a query history item you have already run and try again.');
315+
}
316+
313317
const textDocument = await vscode.workspace.openTextDocument(
314318
vscode.Uri.file(finalSingleItem.query.program.queryPath)
315319
);
@@ -398,6 +402,11 @@ export class QueryHistoryManager extends DisposableObject {
398402
if (!this.assertSingleQuery(finalMultiSelect)) {
399403
return;
400404
}
405+
406+
if (!finalSingleItem) {
407+
throw new Error('No query selected. Select a query history item you have already run and try again.');
408+
}
409+
401410
this.treeDataProvider.setCurrentItem(finalSingleItem);
402411

403412
const now = new Date();
@@ -440,6 +449,10 @@ export class QueryHistoryManager extends DisposableObject {
440449
return;
441450
}
442451

452+
if (!singleItem) {
453+
throw new Error('No query selected. Select a query history item you have already run and try again.');
454+
}
455+
443456
const queryName = singleItem.queryName.endsWith('.ql')
444457
? singleItem.queryName
445458
: 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('No dbscheme. Is your qlpack.yml missing or invalid?');
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)