Add simple error handling to external API usage extraction

This commit is contained in:
Koen Vlaswinkel
2023-04-05 11:33:00 +02:00
parent e37da4f6a4
commit d9b362ddff

View File

@@ -11,10 +11,15 @@ import { qlpackOfDatabase } from "../contextual/queryResolver";
import { file } from "tmp-promise";
import { writeFile } from "fs-extra";
import { dump } from "js-yaml";
import { getOnDiskWorkspaceFolders } from "../helpers";
import {
getOnDiskWorkspaceFolders,
showAndLogExceptionWithTelemetry,
} from "../helpers";
import { DatabaseItem } from "../local-databases";
import { CodeQLCliServer } from "../cli";
import { decodeBqrsToExternalApiUsages } from "./bqrs";
import { redactableError } from "../pure/errors";
import { asError, getErrorMessage } from "../pure/helpers-pure";
export class DataExtensionsEditorView extends AbstractWebview<
ToDataExtensionsEditorMessage,
@@ -71,40 +76,48 @@ export class DataExtensionsEditorView extends AbstractWebview<
}
protected async loadExternalApiUsages(): Promise<void> {
const queryResult = await this.runQuery();
if (!queryResult) {
try {
const queryResult = await this.runQuery();
if (!queryResult) {
await this.clearProgress();
return;
}
await this.showProgress({
message: "Loading results",
step: 1100,
maxStep: 1500,
});
const bqrsPath = queryResult.outputDir.bqrsPath;
const bqrsChunk = await this.getResults(bqrsPath);
if (!bqrsChunk) {
await this.clearProgress();
return;
}
await this.showProgress({
message: "Finalizing results",
step: 1450,
maxStep: 1500,
});
const externalApiUsages = decodeBqrsToExternalApiUsages(bqrsChunk);
await this.postMessage({
t: "setExternalApiUsages",
externalApiUsages,
});
await this.clearProgress();
return;
} catch (err) {
void showAndLogExceptionWithTelemetry(
redactableError(
asError(err),
)`Failed to load external APi usages: ${getErrorMessage(err)}`,
);
}
await this.showProgress({
message: "Loading results",
step: 1100,
maxStep: 1500,
});
const bqrsPath = queryResult.outputDir.bqrsPath;
const bqrsChunk = await this.getResults(bqrsPath);
if (!bqrsChunk) {
await this.clearProgress();
return;
}
await this.showProgress({
message: "Finalizing results",
step: 1450,
maxStep: 1500,
});
const externalApiUsages = decodeBqrsToExternalApiUsages(bqrsChunk);
await this.postMessage({
t: "setExternalApiUsages",
externalApiUsages,
});
await this.clearProgress();
}
private async runQuery(): Promise<CoreCompletedQuery | undefined> {