Skip to content

Commit e37807c

Browse files
author
Dave Bartolomeo
committed
Better error message when odasa is not configured properly
1 parent be72e9b commit e37807c

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

extensions/ql-vscode/src/odasa.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from 'path';
22
import * as child_process from 'child-process-promise';
33
import * as readline from 'readline';
4+
import * as fs from 'fs-extra';
45

56
export interface QLTestHandler {
67
onTestPassed(testId: string): void;
@@ -96,6 +97,11 @@ function getOdasaPath(options: QLOptions): string {
9697
}
9798
}
9899

100+
export async function isOdasaAvailable(options: QLOptions): Promise<boolean> {
101+
const odasaPath = getOdasaPath(options);
102+
return await fs.pathExists(odasaPath);
103+
}
104+
99105
async function runOdasa(command: string, args: string[], options: QLOptions,
100106
matcher: QLOutputMatcher): Promise<void> {
101107

@@ -148,11 +154,19 @@ async function runOdasa(command: string, args: string[], options: QLOptions,
148154
options.registerOnCancellationRequested(() => proc.childProcess.kill());
149155
}
150156

151-
const result = await proc;
152-
if (result.code === 0) {
153-
return;
157+
try {
158+
const result = await proc;
159+
if (result.code === 0) {
160+
return;
161+
}
162+
else {
163+
throw new Error(`'odasa ${command}' failed with exit code '${result.code}'.`);
164+
}
154165
}
155-
else {
156-
throw new Error(`'odasa ${command}' failed with exit code '${result.code}'.`);
166+
catch (e) {
167+
if (options.output) {
168+
options.output(e.message);
169+
}
170+
throw e;
157171
}
158172
}

extensions/ql-vscode/src/test-adapter.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import {
1616
} from 'vscode-test-adapter-api';
1717
import { TestAdapterRegistrar } from 'vscode-test-adapter-util';
1818
import { QLTestFile, QLTestNode, QLTestDirectory, QLTestDiscovery } from './qltest-discovery';
19-
import { Event, EventEmitter, window, Diagnostic, Uri, Range, DiagnosticSeverity, OutputChannel, CancellationToken, workspace, Disposable, CancellationTokenSource } from 'vscode';
19+
import { Event, EventEmitter, window, Diagnostic, Uri, Range, DiagnosticSeverity, OutputChannel, CancellationToken, workspace, Disposable, CancellationTokenSource, commands } from 'vscode';
2020
import { DisposableObject } from 'semmle-vscode-utils';
21-
import { QLTestOptions, QLTestHandler, QLOptions, qlTest } from './odasa';
21+
import { QLTestOptions, QLTestHandler, QLOptions, qlTest, isOdasaAvailable } from './odasa';
2222
import { QLPackDiscovery } from './qlpack-discovery';
2323
import { CodeQLCliServer } from './cli';
24+
import { showAndLogErrorMessage } from './helpers';
2425

2526
/**
2627
* Get the full path of the `.expected` file for the specified QL test.
@@ -324,6 +325,19 @@ export class QLTestAdapter extends DisposableObject implements TestAdapter {
324325
}
325326

326327
try {
328+
if (!await isOdasaAvailable(qlOptions)) {
329+
const action = showAndLogErrorMessage("'codeQL.tests.odasaDistributionPath' does not " +
330+
"point to a distribution of Semmle Core. Semmle Core is required in order to run " +
331+
"CodeQL tests. This requirement will be removed as soon as the CodeQL CLI supports " +
332+
"running tests.",
333+
'Edit Settings');
334+
action.then(response => {
335+
if (response !== undefined) {
336+
commands.executeCommand('workbench.action.openSettings2');
337+
}
338+
});
339+
// Attempt to invoke `odasa` anyway, just to get a more precise error in the log.
340+
}
327341
await qlTest(qlOptions, qlTestOptions, handler);
328342
}
329343
finally {

0 commit comments

Comments
 (0)