diff --git a/extensions/ql-vscode/CHANGELOG.md b/extensions/ql-vscode/CHANGELOG.md index e1c089a6cb3..91363d8f8dc 100644 --- a/extensions/ql-vscode/CHANGELOG.md +++ b/extensions/ql-vscode/CHANGELOG.md @@ -6,6 +6,8 @@ - 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) - 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) - 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) +- Add clearer error message when running a query using a missing or invalid qlpack. [#702](https://github.com/github/vscode-codeql/pull/702) +- 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) ## 1.3.7 - 24 November 2020 diff --git a/extensions/ql-vscode/package.json b/extensions/ql-vscode/package.json index ebe6aa83564..ba4fde1c09f 100644 --- a/extensions/ql-vscode/package.json +++ b/extensions/ql-vscode/package.json @@ -304,7 +304,7 @@ }, { "command": "codeQLQueryHistory.openQuery", - "title": "Open Query", + "title": "Open the query that produced these results", "icon": { "light": "media/light/edit.svg", "dark": "media/dark/edit.svg" diff --git a/extensions/ql-vscode/src/query-history.ts b/extensions/ql-vscode/src/query-history.ts index d0c4d7a1df5..36a0f0d0f64 100644 --- a/extensions/ql-vscode/src/query-history.ts +++ b/extensions/ql-vscode/src/query-history.ts @@ -172,6 +172,7 @@ class HistoryTreeDataProvider extends DisposableObject implements QueryHistoryDa */ const DOUBLE_CLICK_TIME = 500; +const NO_QUERY_SELECTED = 'No query selected. Select a query history item you have already run and try again.'; export class QueryHistoryManager extends DisposableObject { treeDataProvider: HistoryTreeDataProvider; treeView: vscode.TreeView; @@ -310,6 +311,10 @@ export class QueryHistoryManager extends DisposableObject { return; } + if (!finalSingleItem) { + throw new Error(NO_QUERY_SELECTED); + } + const textDocument = await vscode.workspace.openTextDocument( vscode.Uri.file(finalSingleItem.query.program.queryPath) ); @@ -398,6 +403,11 @@ export class QueryHistoryManager extends DisposableObject { if (!this.assertSingleQuery(finalMultiSelect)) { return; } + + if (!finalSingleItem) { + throw new Error(NO_QUERY_SELECTED); + } + this.treeDataProvider.setCurrentItem(finalSingleItem); const now = new Date(); @@ -440,6 +450,10 @@ export class QueryHistoryManager extends DisposableObject { return; } + if (!singleItem) { + throw new Error(NO_QUERY_SELECTED); + } + const queryName = singleItem.queryName.endsWith('.ql') ? singleItem.queryName : singleItem.queryName + '.ql'; diff --git a/extensions/ql-vscode/src/run-queries.ts b/extensions/ql-vscode/src/run-queries.ts index 0c8a09125e3..5541903abaa 100644 --- a/extensions/ql-vscode/src/run-queries.ts +++ b/extensions/ql-vscode/src/run-queries.ts @@ -345,7 +345,7 @@ async function promptUserToSaveChanges(document: TextDocument): Promise else { const yesItem = { title: 'Yes', isCloseAffordance: false }; const alwaysItem = { title: 'Always Save', isCloseAffordance: false }; - const noItem = { title: 'No (run anyway)', isCloseAffordance: false }; + const noItem = { title: 'No (run version on disk)', isCloseAffordance: false }; const cancelItem = { title: 'Cancel', isCloseAffordance: true }; const message = 'Query file has unsaved changes. Save now?'; const chosenItem = await window.showInformationMessage( @@ -478,6 +478,10 @@ export async function compileAndRunQueryAgainstDatabase( // Figure out the library path for the query. const packConfig = await cliServer.resolveLibraryPath(diskWorkspaceFolders, queryPath); + if (!packConfig.dbscheme) { + 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.'); + } + // Check whether the query has an entirely different schema from the // database. (Queries that merely need the database to be upgraded // won't trigger this check)