Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion extensions/ql-vscode/src/codeql-cli/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as semver from "semver";
import { URL } from "url";
import { ExtensionContext, Event } from "vscode";
import { DistributionConfig } from "../config";
import { showAndLogErrorMessage, showAndLogWarningMessage } from "../helpers";
import { extLogger } from "../common";
import { getCodeQlCliVersion } from "./cli-version";
import {
Expand All @@ -23,6 +22,10 @@ import {
InvocationRateLimiter,
InvocationRateLimiterResultKind,
} from "../common/invocation-rate-limiter";
import {
showAndLogErrorMessage,
showAndLogWarningMessage,
} from "../common/vscode/log";

/**
* distribution.ts
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/common/vscode/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {
} from "../../pure/helpers-pure";
import { redactableError } from "../../pure/errors";
import { UserCancellationException } from "./progress";
import { telemetryListener } from "../../telemetry";
import {
showAndLogExceptionWithTelemetry,
showAndLogWarningMessage,
} from "../../helpers";
import { telemetryListener } from "../../telemetry";
} from "./log";

/**
* Create a command manager for VSCode, wrapping registerCommandWithErrorHandling
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/common/vscode/external-files.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Uri, window } from "vscode";
import { AppCommandManager } from "../commands";
import { showAndLogExceptionWithTelemetry } from "../../helpers";
import { showBinaryChoiceDialog } from "./dialog";
import { redactableError } from "../../pure/errors";
import {
asError,
getErrorMessage,
getErrorStack,
} from "../../pure/helpers-pure";
import { showAndLogExceptionWithTelemetry } from "./log";

export async function tryOpenExternalFile(
commandManager: AppCommandManager,
Expand Down
109 changes: 109 additions & 0 deletions extensions/ql-vscode/src/common/vscode/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { window } from "vscode";
import { RedactableError } from "../../pure/errors";
import { telemetryListener } from "../../telemetry";
import { extLogger, OutputChannelLogger } from "../logging";

interface ShowAndLogExceptionOptions extends ShowAndLogOptions {
/** Custom properties to include in the telemetry report. */
extraTelemetryProperties?: { [key: string]: string };
}

interface ShowAndLogOptions {
/** The output logger that will receive the message. */
outputLogger?: OutputChannelLogger;
/** A set of items that will be rendered as actions in the message. */
items?: string[];
/**
* An alternate message that is added to the log, but not displayed in the popup.
* This is useful for adding extra detail to the logs that would be too noisy for the popup.
*/
fullMessage?: string;
}

/**
* Show an error message, log it to the console, and emit redacted information as telemetry
*
* @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(
error: RedactableError,
options: ShowAndLogExceptionOptions = {},
): Promise<string | undefined> {
telemetryListener?.sendError(error, options.extraTelemetryProperties);
return showAndLogErrorMessage(error.fullMessage, options);
}

/**
* Show an error message and log it to the console
*
* @param message The message to show.
* @param options See individual fields on `ShowAndLogOptions` type.
*
* @return A promise that resolves to the selected item or undefined when being dismissed.
*/
export async function showAndLogErrorMessage(
message: string,
options?: ShowAndLogOptions,
): Promise<string | undefined> {
return internalShowAndLog(
dropLinesExceptInitial(message),
window.showErrorMessage,
{ fullMessage: message, ...options },
);
}

function dropLinesExceptInitial(message: string, n = 2) {
return message.toString().split(/\r?\n/).slice(0, n).join("\n");
}

/**
* Show a warning message and log it to the console
*
* @param message The message to show.
* @param options See individual fields on `ShowAndLogOptions` type.
*
* @return A promise that resolves to the selected item or undefined when being dismissed.
*/
export async function showAndLogWarningMessage(
message: string,
options?: ShowAndLogOptions,
): Promise<string | undefined> {
return internalShowAndLog(message, window.showWarningMessage, options);
}

/**
* Show an information message and log it to the console
*
* @param message The message to show.
* @param options See individual fields on `ShowAndLogOptions` type.
*
* @return A promise that resolves to the selected item or undefined when being dismissed.
*/
export async function showAndLogInformationMessage(
message: string,
options?: ShowAndLogOptions,
): Promise<string | undefined> {
return internalShowAndLog(message, window.showInformationMessage, options);
}

type ShowMessageFn = (
message: string,
...items: string[]
) => Thenable<string | undefined>;

async function internalShowAndLog(
message: string,
fn: ShowMessageFn,
{ items = [], outputLogger = extLogger, fullMessage }: ShowAndLogOptions = {},
): Promise<string | undefined> {
const label = "Show Log";
void outputLogger.log(fullMessage || message);
const result = await fn(message, label, ...items);
if (result === label) {
outputLogger.show();
}
return result;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { showAndLogErrorMessage } from "../../helpers";
import {
ExplorerSelectionCommandFunction,
TreeViewContextMultiSelectionCommandFunction,
TreeViewContextSingleSelectionCommandFunction,
} from "../commands";
import { showAndLogErrorMessage } from "./log";

// A hack to match types that are not an array, which is useful to help avoid
// misusing createSingleSelectionCommand, e.g. where T accidentally gets instantiated
Expand Down
3 changes: 2 additions & 1 deletion extensions/ql-vscode/src/compare/compare-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
} from "../common/vscode/abstract-webview";
import { telemetryListener } from "../telemetry";
import { redactableError } from "../pure/errors";
import { showAndLogExceptionWithTelemetry } from "../helpers";

import { showAndLogExceptionWithTelemetry } from "../common/vscode/log";

interface ComparePair {
from: CompletedLocalQueryInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { DatabaseManager } from "../databases/local-databases";
import { ensureDir } from "fs-extra";
import { join } from "path";
import { App } from "../common/app";
import { showAndLogErrorMessage } from "../helpers";
import { withProgress } from "../common/vscode/progress";
import { pickExtensionPackModelFile } from "./extension-pack-picker";
import { showAndLogErrorMessage } from "../common/vscode/log";

const SUPPORTED_LANGUAGES: string[] = ["java", "csharp"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import {
} from "../pure/interface-types";
import { ProgressUpdate } from "../common/vscode/progress";
import { QueryRunner } from "../query-server";
import {
showAndLogErrorMessage,
showAndLogExceptionWithTelemetry,
} from "../helpers";
import { extLogger } from "../common";
import { outputFile, pathExists, readFile } from "fs-extra";
import { load as loadYaml } from "js-yaml";
Expand All @@ -46,6 +42,10 @@ import {
} from "./auto-model";
import { showLlmGeneration } from "../config";
import { getAutoModelUsages } from "./auto-model-usages-query";
import {
showAndLogErrorMessage,
showAndLogExceptionWithTelemetry,
} from "../common/vscode/log";

export class DataExtensionsEditorView extends AbstractWebview<
ToDataExtensionsEditorMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { dump as dumpYaml, load as loadYaml } from "js-yaml";
import { minimatch } from "minimatch";
import { CancellationToken, window } from "vscode";
import { CodeQLCliServer } from "../codeql-cli/cli";
import { showAndLogErrorMessage } from "../helpers";
import {
getOnDiskWorkspaceFolders,
getOnDiskWorkspaceFoldersObjects,
Expand All @@ -14,6 +13,7 @@ import { DatabaseItem } from "../databases/local-databases";
import { getQlPackPath, QLPACK_FILENAMES } from "../pure/ql";
import { getErrorMessage } from "../pure/helpers-pure";
import { ExtensionPack, ExtensionPackModelFile } from "./shared/extension-pack";
import { showAndLogErrorMessage } from "../common/vscode/log";
import { containsPath } from "../pure/files";

const maxStep = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { CoreCompletedQuery, QueryRunner } from "../query-server";
import { dir } from "tmp-promise";
import { writeFile } from "fs-extra";
import { dump as dumpYaml } from "js-yaml";
import { showAndLogExceptionWithTelemetry } from "../helpers";
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
import { TeeLogger } from "../common";
import { isQueryLanguage } from "../common/query-language";
Expand All @@ -14,6 +13,7 @@ import { fetchExternalApiQueries } from "./queries";
import { QueryResultType } from "../pure/new-messages";
import { join } from "path";
import { redactableError } from "../pure/errors";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/log";

export type RunQueryOptions = {
cliServer: Pick<CodeQLCliServer, "resolveQlpacks">;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { CodeQLCliServer } from "../codeql-cli/cli";
import { TeeLogger } from "../common";
import { extensiblePredicateDefinitions } from "./predicates";
import { ProgressCallback } from "../common/vscode/progress";
import { showAndLogExceptionWithTelemetry } from "../helpers";
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
import {
ModeledMethodType,
Expand All @@ -18,6 +17,7 @@ import { file } from "tmp-promise";
import { writeFile } from "fs-extra";
import { dump } from "js-yaml";
import { qlpackOfDatabase } from "../language-support";
import { showAndLogExceptionWithTelemetry } from "../common/vscode/log";

type FlowModelOptions = {
cliServer: CodeQLCliServer;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/databases/code-search-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { retry } from "@octokit/plugin-retry";
import { throttling } from "@octokit/plugin-throttling";
import { Octokit } from "@octokit/rest";
import { Progress, CancellationToken } from "vscode";
import { showAndLogWarningMessage } from "../helpers";
import { Credentials } from "../common/authentication";
import { showAndLogWarningMessage } from "../common/vscode/log";

export async function getCodeSearchRepositories(
query: string,
Expand Down
3 changes: 2 additions & 1 deletion extensions/ql-vscode/src/databases/database-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as Octokit from "@octokit/rest";
import { retry } from "@octokit/plugin-retry";

import { DatabaseManager, DatabaseItem } from "./local-databases";
import { showAndLogInformationMessage, tmpDir } from "../helpers";
import { tmpDir } from "../helpers";
import {
reportStreamProgress,
ProgressCallback,
Expand All @@ -31,6 +31,7 @@ import {
import { Credentials } from "../common/authentication";
import { AppCommandManager } from "../common/commands";
import { ALLOW_HTTP_SETTING } from "../config";
import { showAndLogInformationMessage } from "../common/vscode/log";

/**
* Prompts a user to fetch a database from a remote location. Database is assumed to be an archive file.
Expand Down
8 changes: 4 additions & 4 deletions extensions/ql-vscode/src/databases/local-databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import {
withInheritedProgress,
withProgress,
} from "../common/vscode/progress";
import {
showAndLogErrorMessage,
showAndLogExceptionWithTelemetry,
} from "../helpers";
import {
isLikelyDatabaseRoot,
isLikelyDbLanguageFolder,
Expand All @@ -52,6 +48,10 @@ import {
createMultiSelectionCommand,
createSingleSelectionCommand,
} from "../common/vscode/selection-commands";
import {
showAndLogErrorMessage,
showAndLogExceptionWithTelemetry,
} from "../common/vscode/log";

enum SortOrder {
NameAsc = "NameAsc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { join } from "path";
import { FullDatabaseOptions } from "./database-options";
import { DatabaseItemImpl } from "./database-item-impl";
import { showAndLogExceptionWithTelemetry } from "../../helpers";
import { showNeverAskAgainDialog } from "../../common/vscode/dialog";
import {
getFirstWorkspaceFolder,
Expand All @@ -29,6 +28,7 @@ import { remove } from "fs-extra";
import { containsPath } from "../../pure/files";
import { DatabaseChangedEvent, DatabaseEventKind } from "./database-events";
import { DatabaseResolver } from "./database-resolver";
import { showAndLogExceptionWithTelemetry } from "../../common/vscode/log";

/**
* The name of the key in the workspaceState dictionary in which we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
DatabaseKind,
} from "./database-contents";
import { glob } from "glob";
import { encodeArchiveBasePath } from "../../common/vscode/archive-filesystem-provider";
import {
showAndLogInformationMessage,
showAndLogWarningMessage,
} from "../../helpers";
import { encodeArchiveBasePath } from "../../common/vscode/archive-filesystem-provider";
} from "../../common/vscode/log";

export class DatabaseResolver {
public static async resolveDatabaseContents(
Expand Down
8 changes: 4 additions & 4 deletions extensions/ql-vscode/src/databases/ui/db-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import {
getOwnerFromGitHubUrl,
isValidGitHubOwner,
} from "../../common/github-url-identifier-helper";
import {
showAndLogErrorMessage,
showAndLogInformationMessage,
} from "../../helpers";
import { DisposableObject } from "../../pure/disposable-object";
import {
DbItem,
Expand All @@ -38,6 +34,10 @@ import { DatabasePanelCommands } from "../../common/commands";
import { App } from "../../common/app";
import { QueryLanguage } from "../../common/query-language";
import { getCodeSearchRepositories } from "../code-search-api";
import {
showAndLogErrorMessage,
showAndLogInformationMessage,
} from "../../common/vscode/log";

export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
remoteDatabaseKind: string;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/debugger/debug-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
DebugConfigurationProvider,
WorkspaceFolder,
} from "vscode";
import { showAndLogErrorMessage } from "../helpers";
import { getOnDiskWorkspaceFolders } from "../common/vscode/workspace-folders";
import { LocalQueries } from "../local-queries";
import { getQuickEvalContext, validateQueryPath } from "../run-queries-shared";
import * as CodeQLProtocol from "./debug-protocol";
import { getErrorMessage } from "../pure/helpers-pure";
import { showAndLogErrorMessage } from "../common/vscode/log";

/**
* The CodeQL launch arguments, as specified in "launch.json".
Expand Down
Loading