Add catch handler for discovery failures

Display a reasonable message to users if there is a failure.
This commit is contained in:
Andrew Eisenberg
2020-07-27 07:40:28 -07:00
parent f62cce32da
commit 6a9c9a1eb4
3 changed files with 9 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { DisposableObject } from './vscode-utils/disposable-object';
import { showAndLogErrorMessage } from './helpers';
/**
* Base class for "discovery" operations, which scan the file system to find specific kinds of
@@ -9,7 +10,7 @@ export abstract class Discovery<T> extends DisposableObject {
private retry = false;
private discoveryInProgress = false;
constructor() {
constructor(private readonly name: string) {
super();
}
@@ -59,6 +60,11 @@ export abstract class Discovery<T> extends DisposableObject {
this.update(results);
}
});
discoveryPromise.catch(err => {
showAndLogErrorMessage(`${this.name} failed. Reason: ${err.message}`);
});
discoveryPromise.finally(() => {
if (this.retry) {
// Another refresh request came in while we were still running a previous discovery

View File

@@ -20,7 +20,7 @@ export class QLPackDiscovery extends Discovery<QlpacksInfo> {
private readonly workspaceFolder: WorkspaceFolder,
private readonly cliServer: CodeQLCliServer
) {
super();
super('QL Pack Discovery');
// Watch for any changes to `qlpack.yml` files in this workspace folder.
// TODO: The CLI server should tell us what paths to watch for.

View File

@@ -119,7 +119,7 @@ export class QLTestDiscovery extends Discovery<QLTestDiscoveryResults> {
private readonly workspaceFolder: WorkspaceFolder,
private readonly cliServer: CodeQLCliServer
) {
super();
super('QL Test Discovery');
this.push(this.qlPackDiscovery.onDidChangeQLPacks(this.handleDidChangeQLPacks, this));
this.push(this.watcher.onDidChange(this.handleDidChange, this));