Skip to content

Commit 3d8843f

Browse files
committed
fix: Readable error message for invalid file
Display an understandable error message when trying to Run Query on a qll file. Closes 201
1 parent 5852661 commit 3d8843f

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

extensions/ql-vscode/src/extension.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let isInstallingOrUpdatingDistribution = false;
5656
*
5757
* @param excludedCommands List of commands for which we should not register error stubs.
5858
*/
59-
function registerErrorStubs(excludedCommands: string[], stubGenerator: (command: string) => () => void) {
59+
function registerErrorStubs(excludedCommands: string[], stubGenerator: (command: string) => () => void): void {
6060
// Remove existing stubs
6161
errorStubs.forEach(stub => stub.dispose());
6262

@@ -229,7 +229,7 @@ export async function activate(ctx: ExtensionContext): Promise<void> {
229229
});
230230
}
231231

232-
async function activateWithInstalledDistribution(ctx: ExtensionContext, distributionManager: DistributionManager) {
232+
async function activateWithInstalledDistribution(ctx: ExtensionContext, distributionManager: DistributionManager): Promise<void> {
233233
beganMainExtensionActivation = true;
234234
// Remove any error stubs command handlers left over from first part
235235
// of activation.
@@ -270,7 +270,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
270270
await intm.showResults(query, forceReveal, false);
271271
}
272272

273-
async function compileAndRunQuery(quickEval: boolean, selectedQuery: Uri | undefined) {
273+
async function compileAndRunQuery(quickEval: boolean, selectedQuery: Uri | undefined): Promise<void> {
274274
if (qs !== undefined) {
275275
try {
276276
const dbItem = await databaseUI.getDatabaseItem();
@@ -294,7 +294,7 @@ async function activateWithInstalledDistribution(ctx: ExtensionContext, distribu
294294

295295
ctx.subscriptions.push(tmpDirDisposal);
296296

297-
let client = new LanguageClient('CodeQL Language Server', () => spawnIdeServer(qlConfigurationListener), {
297+
const client = new LanguageClient('CodeQL Language Server', () => spawnIdeServer(qlConfigurationListener), {
298298
documentSelector: [
299299
{ language: 'ql', scheme: 'file' },
300300
{ language: 'yaml', scheme: 'file', pattern: '**/qlpack.yml' }

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ async function determineSelectedQuery(selectedResourceUri: vscode.Uri | undefine
334334
if (queryUri.scheme !== 'file') {
335335
throw new Error('Can only run queries that are on disk.');
336336
}
337-
const queryPath = queryUri.fsPath;
337+
const queryPath = queryUri.fsPath || '';
338+
339+
if (!queryPath.endsWith('.ql')) {
340+
throw new Error('The selected resource is not a QL file.');
341+
}
338342

339343
// Whether we chose the file from the active editor or from a context menu,
340344
// if the same file is open with unsaved changes in the active editor,

0 commit comments

Comments
 (0)