Skip to content

Commit 4cf7f0b

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 4cf7f0b

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

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)