Move showAndLogExceptionWithTelemetry out of vscode directory

This commit is contained in:
Koen Vlaswinkel
2023-06-14 11:59:09 +02:00
parent d03d355513
commit 7a76e20841
27 changed files with 86 additions and 77 deletions

View File

@@ -1,4 +1,6 @@
import { NotificationLogger } from "./notification-logger";
import { AppTelemetry } from "../telemetry";
import { RedactableError } from "../../pure/errors";
export interface ShowAndLogOptions {
/**
@@ -87,3 +89,28 @@ async function internalShowAndLog(
void logger.log(fullMessage || message);
await fn.bind(logger)(message);
}
interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
/** Custom properties to include in the telemetry report. */
extraTelemetryProperties?: { [key: string]: string };
}
/**
* Show an error message, log it to the console, and emit redacted information as telemetry
*
* @param logger The logger that will receive the message.
* @param telemetry The telemetry instance to use for reporting.
* @param error The error to show. Only redacted information will be included in the telemetry.
* @param options See individual fields on `ShowAndLogExceptionOptions` type.
*
* @return A promise that resolves to the selected item or undefined when being dismissed.
*/
export async function showAndLogExceptionWithTelemetry(
logger: NotificationLogger,
telemetry: AppTelemetry | undefined,
error: RedactableError,
options: ShowAndLogExceptionOptions = {},
): Promise<void> {
telemetry?.sendError(error, options.extraTelemetryProperties);
return showAndLogErrorMessage(logger, error.fullMessage, options);
}

View File

@@ -4,6 +4,7 @@ import {
extLogger,
NotificationLogger,
showAndLogWarningMessage,
showAndLogExceptionWithTelemetry,
} from "../logging";
import {
asError,
@@ -13,7 +14,6 @@ import {
import { redactableError } from "../../pure/errors";
import { UserCancellationException } from "./progress";
import { telemetryListener } from "./telemetry";
import { showAndLogExceptionWithTelemetry } from "./logging";
import { AppTelemetry } from "../telemetry";
/**

View File

@@ -7,8 +7,7 @@ import {
getErrorMessage,
getErrorStack,
} from "../../pure/helpers-pure";
import { extLogger } from "../logging";
import { showAndLogExceptionWithTelemetry } from "./logging";
import { extLogger, showAndLogExceptionWithTelemetry } from "../logging";
import { telemetryListener } from "./telemetry";
export async function tryOpenExternalFile(

View File

@@ -1,32 +0,0 @@
import {
NotificationLogger,
showAndLogErrorMessage,
ShowAndLogOptions,
} from "../logging";
import { RedactableError } from "../../pure/errors";
import { AppTelemetry } from "../telemetry";
interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
/** Custom properties to include in the telemetry report. */
extraTelemetryProperties?: { [key: string]: string };
}
/**
* Show an error message, log it to the console, and emit redacted information as telemetry
*
* @param logger The logger that will receive the message.
* @param telemetry The telemetry instance to use for reporting.
* @param error The error to show. Only redacted information will be included in the telemetry.
* @param options See individual fields on `ShowAndLogExceptionOptions` type.
*
* @return A promise that resolves to the selected item or undefined when being dismissed.
*/
export async function showAndLogExceptionWithTelemetry(
logger: NotificationLogger,
telemetry: AppTelemetry | undefined,
error: RedactableError,
options: ShowAndLogExceptionOptions = {},
): Promise<void> {
telemetry?.sendError(error, options.extraTelemetryProperties);
return showAndLogErrorMessage(logger, error.fullMessage, options);
}

View File

@@ -6,7 +6,7 @@ import {
QueryCompareResult,
} from "../pure/interface-types";
import { extLogger, Logger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import { CodeQLCliServer } from "../codeql-cli/cli";
import { DatabaseManager } from "../databases/local-databases";
import { jumpToLocation } from "../databases/local-databases/locations";

View File

@@ -17,7 +17,10 @@ import {
} from "../pure/interface-types";
import { ProgressUpdate } from "../common/vscode/progress";
import { QueryRunner } from "../query-server";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogErrorMessage,
} from "../common/logging";
import { outputFile, pathExists, readFile } from "fs-extra";
import { load as loadYaml } from "js-yaml";
import { DatabaseItem, DatabaseManager } from "../databases/local-databases";
@@ -42,7 +45,6 @@ import {
} from "./auto-model";
import { showLlmGeneration } from "../config";
import { getAutoModelUsages } from "./auto-model-usages-query";
import { showAndLogErrorMessage } from "../common/logging";
export class DataExtensionsEditorView extends AbstractWebview<
ToDataExtensionsEditorMessage,

View File

@@ -4,7 +4,7 @@ import { writeFile } from "fs-extra";
import { dump as dumpYaml } from "js-yaml";
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
import { extLogger, TeeLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import { isQueryLanguage } from "../common/query-language";
import { CancellationToken } from "vscode";
import { CodeQLCliServer } from "../codeql-cli/cli";

View File

@@ -4,7 +4,7 @@ import { basename } from "path";
import { QueryRunner } from "../query-server";
import { CodeQLCliServer } from "../codeql-cli/cli";
import { extLogger, TeeLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import { extensiblePredicateDefinitions } from "./predicates";
import { ProgressCallback } from "../common/vscode/progress";
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";

View File

@@ -32,7 +32,10 @@ import {
isLikelyDatabaseRoot,
isLikelyDbLanguageFolder,
} from "./local-databases/db-contents-heuristics";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogErrorMessage,
} from "../common/logging";
import {
importArchiveDatabase,
promptImportGithubDatabase,
@@ -48,7 +51,6 @@ import {
createMultiSelectionCommand,
createSingleSelectionCommand,
} from "../common/vscode/selection-commands";
import { showAndLogErrorMessage } from "../common/logging";
enum SortOrder {
NameAsc = "NameAsc",

View File

@@ -1,6 +1,6 @@
import vscode, { ExtensionContext } from "vscode";
import { extLogger, Logger } from "../../common";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
import { DisposableObject } from "../../pure/disposable-object";
import { App } from "../../common/app";
import { QueryRunner } from "../../query-server";

View File

@@ -80,7 +80,12 @@ import {
ProgressReporter,
queryServerLogger,
} from "./common";
import { showAndLogExceptionWithTelemetry } from "./common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogErrorMessage,
showAndLogInformationMessage,
showAndLogWarningMessage,
} from "./common/logging";
import { QueryHistoryManager } from "./query-history/query-history-manager";
import { CompletedLocalQueryInfo } from "./query-results";
import {
@@ -129,11 +134,6 @@ import { TestRunner } from "./query-testing/test-runner";
import { TestManagerBase } from "./query-testing/test-manager-base";
import { NewQueryRunner, QueryRunner, QueryServerClient } from "./query-server";
import { QueriesModule } from "./queries-panel/queries-module";
import {
showAndLogErrorMessage,
showAndLogInformationMessage,
showAndLogWarningMessage,
} from "./common/logging";
/**
* extension.ts

View File

@@ -28,7 +28,7 @@ import { asError, getErrorMessage } from "../../pure/helpers-pure";
import { redactableError } from "../../pure/errors";
import { AstViewerCommands } from "../../common/commands";
import { extLogger } from "../../common";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
import { telemetryListener } from "../../common/vscode/telemetry";
export interface AstItem {

View File

@@ -18,7 +18,7 @@ import {
import { CodeQLCliServer } from "../../codeql-cli/cli";
import { DatabaseItem } from "../../databases/local-databases";
import { extLogger, TeeLogger } from "../../common";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
import { CancellationToken } from "vscode";
import { ProgressCallback } from "../../common/vscode/progress";
import { CoreCompletedQuery, QueryRunner } from "../../query-server";

View File

@@ -6,7 +6,7 @@ import { getErrorMessage } from "../pure/helpers-pure";
import { redactableError } from "../pure/errors";
import { AppCommandManager, QueryEditorCommands } from "../common/commands";
import { extLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import { telemetryListener } from "../common/vscode/telemetry";
type QueryEditorOptions = {

View File

@@ -1,5 +1,8 @@
import { BaseLogger, extLogger, Logger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogWarningMessage,
} from "../common/logging";
import { CoreQueryResults } from "../query-server";
import { QueryHistoryManager } from "../query-history/query-history-manager";
import { DatabaseItem } from "../databases/local-databases";
@@ -17,7 +20,6 @@ import { CodeQLCliServer } from "../codeql-cli/cli";
import { QueryResultType } from "../pure/new-messages";
import { redactableError } from "../pure/errors";
import { LocalQueries } from "./local-queries";
import { showAndLogWarningMessage } from "../common/logging";
import { tryGetQueryMetadata } from "../codeql-cli/query-metadata";
import { telemetryListener } from "../common/vscode/telemetry";

View File

@@ -41,7 +41,7 @@ import {
ParsedResultSets,
} from "../pure/interface-types";
import { extLogger, Logger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import {
CompletedQueryInfo,
interpretResultsSarif,

View File

@@ -7,12 +7,14 @@ import {
withProgress,
} from "../common/vscode/progress";
import { extLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogInformationMessage,
} from "../common/logging";
import { asError, getErrorStack } from "../pure/helpers-pure";
import { redactableError } from "../pure/errors";
import { PACKS_BY_QUERY_LANGUAGE } from "../common/query-language";
import { PackagingCommands } from "../common/commands";
import { showAndLogInformationMessage } from "../common/logging";
import { telemetryListener } from "../common/vscode/telemetry";
type PackagingOptions = {

View File

@@ -13,7 +13,7 @@ import { asError, getErrorMessage } from "../pure/helpers-pure";
import { redactableError } from "../pure/errors";
import { EvalLogViewerCommands } from "../common/commands";
import { extLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
import { telemetryListener } from "../common/vscode/telemetry";
export interface EvalLogTreeItem {

View File

@@ -13,7 +13,7 @@ import { QueryHistoryDto, QueryHistoryItemDto } from "./query-history-dto";
import { mapQueryHistoryToDomainModel } from "./query-history-dto-mapper";
import { mapQueryHistoryToDto } from "./query-history-domain-mapper";
import { extLogger } from "../../common";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
import { telemetryListener } from "../../common/vscode/telemetry";
const ALLOWED_QUERY_HISTORY_VERSIONS = [1, 2];

View File

@@ -13,7 +13,10 @@ import { tmpDir } from "../../tmp-dir";
import { ProgressCallback } from "../../common/vscode/progress";
import { QueryMetadata } from "../../pure/interface-types";
import { extLogger, Logger } from "../../common";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogWarningMessage,
} from "../../common/logging";
import * as messages from "../../pure/legacy-messages";
import * as newMessages from "../../pure/new-messages";
import * as qsClient from "./query-server-client";
@@ -23,7 +26,6 @@ import { QueryEvaluationInfo, QueryOutputDir } from "../../run-queries-shared";
import { redactableError } from "../../pure/errors";
import { CoreQueryResults, CoreQueryTarget } from "../query-runner";
import { Position } from "../../pure/messages-shared";
import { showAndLogWarningMessage } from "../../common/logging";
import { ensureDirSync } from "fs-extra";
import { telemetryListener } from "../../common/vscode/telemetry";

View File

@@ -6,7 +6,7 @@ import {
UserCancellationException,
} from "../../common/vscode/progress";
import { extLogger } from "../../common";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../../common/logging";
import * as messages from "../../pure/legacy-messages";
import * as qsClient from "./query-server-client";
import * as tmp from "tmp-promise";

View File

@@ -6,9 +6,11 @@ import { asError, getErrorMessage } from "../pure/helpers-pure";
import { redactableError } from "../pure/errors";
import { access } from "fs-extra";
import { BaseLogger, extLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogWarningMessage,
} from "../common/logging";
import { DisposableObject } from "../pure/disposable-object";
import { showAndLogWarningMessage } from "../common/logging";
import { telemetryListener } from "../common/vscode/telemetry";
async function isFileAccessible(uri: Uri): Promise<boolean> {

View File

@@ -12,7 +12,7 @@ import {
import { DataFlowPaths } from "./shared/data-flow-paths";
import { redactableError } from "../pure/errors";
import { extLogger } from "../common";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../common/logging";
export class DataFlowPathsView extends AbstractWebview<
ToDataFlowPathsMessage,

View File

@@ -71,8 +71,8 @@ import {
} from "./repo-states-store";
import { GITHUB_AUTH_PROVIDER_ID } from "../common/vscode/authentication";
import { FetchError } from "node-fetch";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogInformationMessage,
showAndLogWarningMessage,
} from "../common/logging";

View File

@@ -3,7 +3,10 @@ import {
AbstractWebview,
WebviewPanelConfig,
} from "../common/vscode/abstract-webview";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/logging";
import {
showAndLogExceptionWithTelemetry,
showAndLogWarningMessage,
} from "../common/logging";
import {
FromVariantAnalysisMessage,
ToVariantAnalysisMessage,
@@ -27,7 +30,6 @@ import {
getVariantAnalysisDefaultResultsFilter,
getVariantAnalysisDefaultResultsSort,
} from "../config";
import { showAndLogWarningMessage } from "../common/logging";
export class VariantAnalysisView
extends AbstractWebview<ToVariantAnalysisMessage, FromVariantAnalysisMessage>

View File

@@ -5,15 +5,16 @@ import { CodeQLCliServer } from "../../../../src/codeql-cli/cli";
import { getErrorMessage } from "../../../../src/pure/helpers-pure";
import * as log from "../../../../src/common/logging/notifications";
import * as vscodeLog from "../../../../src/common/vscode/logging";
import {
handleDownloadPacks,
handleInstallPackDependencies,
} from "../../../../src/packaging";
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
import { getActivatedExtension } from "../../global.helper";
import { showAndLogInformationMessage } from "../../../../src/common/logging";
import { showAndLogExceptionWithTelemetry } from "../../../../src/common/vscode/logging";
import {
showAndLogInformationMessage,
showAndLogExceptionWithTelemetry,
} from "../../../../src/common/logging";
describe("Packaging commands", () => {
let cli: CodeQLCliServer;
@@ -35,7 +36,7 @@ describe("Packaging commands", () => {
.spyOn(window, "showInputBox")
.mockResolvedValue(undefined);
showAndLogExceptionWithTelemetrySpy = jest
.spyOn(vscodeLog, "showAndLogExceptionWithTelemetry")
.spyOn(log, "showAndLogExceptionWithTelemetry")
.mockResolvedValue(undefined);
showAndLogInformationMessageSpy = jest
.spyOn(log, "showAndLogInformationMessage")

View File

@@ -11,9 +11,9 @@ import { readdir, readFile } from "fs-extra";
import { load } from "js-yaml";
import { dirname, join } from "path";
import { fetchExternalApiQueries } from "../../../../src/data-extensions-editor/queries";
import * as vscodeLog from "../../../../src/common/vscode/logging";
import * as log from "../../../../src/common/logging/notifications";
import { RedactableError } from "../../../../src/pure/errors";
import { showAndLogExceptionWithTelemetry } from "../../../../src/common/vscode/logging";
import { showAndLogExceptionWithTelemetry } from "../../../../src/common/logging";
function createMockUri(path = "/a/b/c/foo"): Uri {
return {
@@ -140,7 +140,7 @@ describe("readQueryResults", () => {
beforeEach(() => {
showAndLogExceptionWithTelemetrySpy = jest.spyOn(
vscodeLog,
log,
"showAndLogExceptionWithTelemetry",
);
});
@@ -153,7 +153,7 @@ describe("readQueryResults", () => {
expect(await readQueryResults(options)).toBeUndefined();
expect(showAndLogExceptionWithTelemetrySpy).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
undefined,
expect.any(RedactableError),
);
});
@@ -187,7 +187,7 @@ describe("readQueryResults", () => {
expect(await readQueryResults(options)).toBeUndefined();
expect(showAndLogExceptionWithTelemetrySpy).toHaveBeenCalledWith(
expect.anything(),
expect.anything(),
undefined,
expect.any(RedactableError),
);
});