Skip to content

Commit b5e7087

Browse files
committed
Fix failing test
Also, small change to ensure `qlpackOfDatabase` never returns undefined. It will either return a value or throw.
1 parent 2516a62 commit b5e7087

4 files changed

Lines changed: 8 additions & 10 deletions

File tree

extensions/ql-vscode/src/contextual/locationFinder.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ export async function getLocationsForUriString(
5252
}
5353

5454
const qlpack = await qlpackOfDatabase(cli, db);
55-
if (qlpack === undefined) {
56-
throw new Error('Can\'t infer qlpack from database source archive');
57-
}
5855
const templates = createTemplates(uri.pathWithinSourceArchive);
5956

6057
const links: FullLocationLink[] = [];

extensions/ql-vscode/src/contextual/queryResolver.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import {
1212
import { CodeQLCliServer } from '../cli';
1313
import { DatabaseItem } from '../databases';
1414

15-
export async function qlpackOfDatabase(cli: CodeQLCliServer, db: DatabaseItem): Promise<string | undefined> {
16-
if (db.contents === undefined)
17-
return undefined;
15+
export async function qlpackOfDatabase(cli: CodeQLCliServer, db: DatabaseItem): Promise<string> {
16+
if (db.contents === undefined) {
17+
throw new Error('Database is invalid and cannot infer QLPack.');
18+
}
1819
const datasetPath = db.contents.datasetUri.fsPath;
1920
const dbscheme = await helpers.getPrimaryDbscheme(datasetPath);
2021
return await helpers.getQlPackForDbscheme(cli, dbscheme);

extensions/ql-vscode/src/contextual/templateProvider.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ export class TemplatePrintAstProvider {
156156
}
157157

158158
const qlpack = await qlpackOfDatabase(this.cli, db);
159-
if (!qlpack) {
160-
throw new Error('Can\'t infer qlpack from database source archive');
161-
}
162159
const queries = await resolveQueries(this.cli, qlpack, KeyType.PrintAstQuery);
163160
if (queries.length > 1) {
164161
throw new Error('Found multiple Print AST queries. Can\'t continue');

extensions/ql-vscode/src/vscode-tests/no-workspace/contextual/queryResolver.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('queryResolver', () => {
1717
let module: Record<string, Function>;
1818
let writeFileSpy: sinon.SinonSpy;
1919
let getQlPackForDbschemeSpy: sinon.SinonStub;
20+
let getPrimaryDbschemeSpy: sinon.SinonStub;
2021
let mockCli: Record<string, sinon.SinonStub>;
2122
beforeEach(() => {
2223
mockCli = {
@@ -70,20 +71,22 @@ describe('queryResolver', () => {
7071
};
7172
const result = await module.qlpackOfDatabase(mockCli, db);
7273
expect(result).to.eq('my-qlpack');
73-
expect(getQlPackForDbschemeSpy).to.have.been.calledWith(mockCli, '/path/to/database');
74+
expect(getPrimaryDbschemeSpy).to.have.been.calledWith('/path/to/database');
7475
});
7576
});
7677

7778
function createModule() {
7879
writeFileSpy = sinon.spy();
7980
getQlPackForDbschemeSpy = sinon.stub();
81+
getPrimaryDbschemeSpy = sinon.stub();
8082
return proxyquire('../../../contextual/queryResolver', {
8183
'fs-extra': {
8284
writeFile: writeFileSpy
8385
},
8486

8587
'../helpers': {
8688
getQlPackForDbscheme: getQlPackForDbschemeSpy,
89+
getPrimaryDbscheme: getPrimaryDbschemeSpy,
8790
getOnDiskWorkspaceFolders: () => ({}),
8891
showAndLogErrorMessage: () => ({})
8992
}

0 commit comments

Comments
 (0)