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
1 change: 0 additions & 1 deletion extensions/ql-vscode/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default tseslint.config(

// Rules disabled during eslint 9 migration
"github/filenames-match-regex": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/codeql-cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class CodeQLCliServer implements Disposable {
} catch (e) {
// We are probably fine here, the process has already closed stdin.
void this.logger.log(
`Shutdown request failed: process stdin may have already closed. The error was ${e}`,
`Shutdown request failed: process stdin may have already closed. The error was ${getErrorMessage(e)}`,
);
void this.logger.log("Stopping the process anyway.");
}
Expand Down Expand Up @@ -748,7 +748,7 @@ export class CodeQLCliServer implements Disposable {
} else {
reject(
new Error(
`${command} ${commandArgs.join(" ")} failed with code ${code}`,
`${command.join(" ")} ${commandArgs.join(" ")} failed with code ${code}`,
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command variable appears to be a string in the original code, not an array. Calling .join(" ") on a string will cause a runtime error. This should likely be just ${command} or the variable type needs to be verified.

Suggested change
`${command.join(" ")} ${commandArgs.join(" ")} failed with code ${code}`,
`${command} ${commandArgs.join(" ")} failed with code ${code}`,

Copilot uses AI. Check for mistakes.

),
);
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/codeql-cli/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class ExtensionSpecificDistributionManager {
} catch (e) {
void extLogger.log(
"WARNING: Tried to remove corrupted CodeQL CLI at " +
`${this.getDistributionStoragePath()} but encountered an error: ${e}.`,
`${this.getDistributionStoragePath()} but encountered an error: ${getErrorMessage(e)}.`,
);
}
}
Expand Down Expand Up @@ -457,7 +457,7 @@ class ExtensionSpecificDistributionManager {
} catch (e) {
void extLogger.log(
`Tried to clean up old version of CLI at ${this.getDistributionStoragePath()} ` +
`but encountered an error: ${e}.`,
`but encountered an error: ${getErrorMessage(e)}.`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/codeql-cli/query-language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function askForLanguage(
if (!isQueryLanguage(language)) {
void showAndLogErrorMessage(
extLogger,
`Language '${language}' is not supported. Only languages ${Object.values(
`Language '${language as string}' is not supported. Only languages ${Object.values(
QueryLanguage,
).join(", ")} are supported.`,
);
Expand Down
5 changes: 4 additions & 1 deletion extensions/ql-vscode/src/codeql-cli/query-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CodeQLCliServer } from "./cli";
import type { QueryMetadata } from "../common/interface-types";
import { extLogger } from "../common/logging/vscode";
import { getErrorMessage } from "../common/helpers-pure";

/**
* Gets metadata for a query, if it exists.
Expand All @@ -16,7 +17,9 @@ export async function tryGetQueryMetadata(
return await cliServer.resolveMetadata(queryPath);
} catch (e) {
// Ignore errors and provide no metadata.
void extLogger.log(`Couldn't resolve metadata for ${queryPath}: ${e}`);
void extLogger.log(
`Couldn't resolve metadata for ${queryPath}: ${getErrorMessage(e)}`,
);
return;
}
}
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/common/short-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ async function expandShortPathComponent(
}
} catch (e) {
// Can't read stats for the child, so skip it.
void logger.log(`Error reading stats for child: ${e}`);
void logger.log(`Error reading stats for child: ${getErrorMessage(e)}`);
}
}
} catch (e) {
// Can't read the directory, so we won't be able to find this in the directory listing.
void logger.log(`Error reading directory: ${e}`);
void logger.log(`Error reading directory: ${getErrorMessage(e)}`);
return shortBase;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const sourceArchiveUriAuthorityPattern = /^(\d+)-(\d+)$/;
class InvalidSourceArchiveUriError extends Error {
constructor(uri: Uri) {
super(
`Can't decode uri ${uri}: authority should be of the form startIndex-endIndex (where both indices are integers).`,
`Can't decode uri ${uri.toString()}: authority should be of the form startIndex-endIndex (where both indices are integers).`,
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/ql-vscode/src/common/vscode/webview-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function getHtmlForWebview(
<body>
<div id=root data-view="${view}">
</div>
<script nonce="${nonce}" src="${scriptWebviewUri}">
<script nonce="${nonce}" src="${scriptWebviewUri.toString()}">
</script>
</body>
</html>`;
Expand All @@ -101,9 +101,9 @@ function getNonce(): string {
}

function createStylesLinkWithNonce(nonce: string, uri: Uri): string {
return `<link nonce="${nonce}" rel="stylesheet" href="${uri}">`;
return `<link nonce="${nonce}" rel="stylesheet" href="${uri.toString()}">`;
}

function createStylesLinkWithoutNonce(uri: Uri): string {
return `<link rel="stylesheet" href="${uri}">`;
return `<link rel="stylesheet" href="${uri.toString()}">`;
}
6 changes: 3 additions & 3 deletions extensions/ql-vscode/src/databases/local-databases-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export class DatabaseUI extends DisposableObject {
// This specifically refers to the database folder in
// https://github.com/github/codespaces-codeql
const uri = Uri.parse(
`${workspace.workspaceFolders[0].uri}/.tours/codeql-tutorial-database`,
`${workspace.workspaceFolders[0].uri.toString()}/.tours/codeql-tutorial-database`,
);

const databaseItem = this.databaseManager.findDatabaseItem(uri);
Expand Down Expand Up @@ -1062,14 +1062,14 @@ export class DatabaseUI extends DisposableObject {

if (!validFileTypes.includes(entry[1])) {
void this.app.logger.log(
`Skipping import for '${entry}', invalid file type: ${entry[1]}`,
`Skipping import for '${entry[0]}', invalid file type: ${entry[1]}`,
);
continue;
}

try {
const databaseUri = Uri.joinPath(uri, entry[0]);
void this.app.logger.log(`Importing from ${databaseUri}`);
void this.app.logger.log(`Importing from ${databaseUri.toString()}`);

const database = await this.importDatabase(
databaseUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ const DB_LIST = "databaseList";
*/
function eventFired<T>(
event: vscode.Event<T>,
eventName: string,
timeoutMs = 1000,
): Promise<T | undefined> {
return new Promise((res, _rej) => {
const timeout = setTimeout(() => {
void extLogger.log(
`Waiting for event ${event} timed out after ${timeoutMs}ms`,
`Waiting for event '${eventName}' timed out after ${timeoutMs}ms`,
);
res(undefined);
dispose();
Expand Down Expand Up @@ -256,7 +257,7 @@ export class DatabaseManager extends DisposableObject {
private async reimportTestDatabase(databaseUri: vscode.Uri): Promise<void> {
const dbItem = this.findDatabaseItem(databaseUri);
if (dbItem === undefined || dbItem.origin?.type !== "testproj") {
throw new Error(`Database ${databaseUri} is not a testproj.`);
throw new Error(`Database ${databaseUri.toString()} is not a testproj.`);
}

await this.removeDatabaseItem(dbItem);
Expand Down Expand Up @@ -474,7 +475,10 @@ export class DatabaseManager extends DisposableObject {
});
// vscode api documentation says we must to wait for this event
// between multiple `updateWorkspaceFolders` calls.
await eventFired(vscode.workspace.onDidChangeWorkspaceFolders);
await eventFired(
vscode.workspace.onDidChangeWorkspaceFolders,
"vscode.workspace.onDidChangeWorkspaceFolders",
);
}
}

Expand Down Expand Up @@ -561,7 +565,7 @@ export class DatabaseManager extends DisposableObject {
// When loading from persisted state, leave invalid databases in the list. They will be
// marked as invalid, and cannot be set as the current database.
void this.logger.log(
`Error loading database ${database.uri}: ${e}.`,
`Error loading database ${database.uri}: ${getErrorMessage(e)}.`,
);
}
}
Expand Down
19 changes: 11 additions & 8 deletions extensions/ql-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function getCommands(
"codeQL.copyVersion": async () => {
const text = `CodeQL extension version: ${
extension?.packageJSON.version
} \nCodeQL CLI version: ${await getCliVersion()} \nPlatform: ${platform()} ${arch()}`;
} \nCodeQL CLI version: ${(await getCliVersion()).toString()} \nPlatform: ${platform()} ${arch()}`;
await env.clipboard.writeText(text);
void showAndLogInformationMessage(extLogger, text);
},
Expand Down Expand Up @@ -457,8 +457,8 @@ export async function activate(

void showAndLogWarningMessage(
extLogger,
`You are using an unsupported version of the CodeQL CLI (${ver.version}). ` +
`The minimum supported version is ${CliVersionConstraint.OLDEST_SUPPORTED_CLI_VERSION}. ` +
`You are using an unsupported version of the CodeQL CLI (${ver.version.toString()}). ` +
`The minimum supported version is ${CliVersionConstraint.OLDEST_SUPPORTED_CLI_VERSION.toString()}. ` +
`Please upgrade to a newer version of the CodeQL CLI.`,
);
unsupportedWarningShown = true;
Expand Down Expand Up @@ -615,10 +615,13 @@ async function installOrUpdateDistribution(
} else if (e instanceof GithubApiError) {
void alertFunction(
extLogger,
`Encountered GitHub API error while trying to ${taskDescription}. ${e}`,
`Encountered GitHub API error while trying to ${taskDescription}. ${getErrorMessage(e)}`,
);
}
void alertFunction(extLogger, `Unable to ${taskDescription}. ${e}`);
void alertFunction(
extLogger,
`Unable to ${taskDescription}. ${getErrorMessage(e)}`,
);
} finally {
isInstallingOrUpdatingDistribution = false;
}
Expand All @@ -640,11 +643,11 @@ async function getDistributionDisplayingDistributionWarnings(
case DistributionKind.ExtensionManaged:
return 'Please update the CodeQL CLI by running the "CodeQL: Check for CLI Updates" command.';
case DistributionKind.CustomPathConfig:
return `Please update the "CodeQL CLI Executable Path" setting to point to a CLI in the version range ${codeQlVersionRange}.`;
return `Please update the "CodeQL CLI Executable Path" setting to point to a CLI in the version range ${codeQlVersionRange.toString()}.`;
case DistributionKind.PathEnvironmentVariable:
return (
`Please update the CodeQL CLI on your PATH to a version compatible with ${codeQlVersionRange}, or ` +
`set the "CodeQL CLI Executable Path" setting to the path of a CLI version compatible with ${codeQlVersionRange}.`
`Please update the CodeQL CLI on your PATH to a version compatible with ${codeQlVersionRange.toString()}, or ` +
`set the "CodeQL CLI Executable Path" setting to the path of a CLI version compatible with ${codeQlVersionRange.toString()}.`
);
}
})();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class AstViewerDataProvider
const treeItem = new TreeItem(item.label || "", state);
treeItem.description = line ? `Line ${line}` : "";
treeItem.id = String(item.id);
treeItem.tooltip = `${treeItem.description} ${treeItem.label}`;
treeItem.tooltip = `${treeItem.description} ${typeof treeItem.label === "string" ? treeItem.label : (treeItem.label?.label ?? "")}`;
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This line is extremely long and hard to read. Consider extracting the label logic into a variable: const labelText = typeof treeItem.label === "string" ? treeItem.label : (treeItem.label?.label ?? ""); treeItem.tooltip = \${treeItem.description} ${labelText}`;`

Suggested change
treeItem.tooltip = `${treeItem.description} ${typeof treeItem.label === "string" ? treeItem.label : (treeItem.label?.label ?? "")}`;
const labelText = typeof treeItem.label === "string" ? treeItem.label : (treeItem.label?.label ?? "");
treeItem.tooltip = `${treeItem.description} ${labelText}`;

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit ugly but the type of treeItem.label is string | TreeItemLabel | undefined and it doesn't seem that TreeItemLabel implements toString().

treeItem.command = {
command: "codeQLAstViewer.gotoCode",
title: "Go To Code",
tooltip: `Go To ${item.location}`,
tooltip: "Go To Code",
arguments: [item],
};
return treeItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function previewQueryHelp(
telemetryListener,
errorMessage,
{
fullMessage: `${errorMessage}\n${getErrorMessage(e)}`,
fullMessage: `${errorMessage.fullMessage}\n${getErrorMessage(e)}`,
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable errorMessage is being treated as an object with a fullMessage property, but the original code suggests it should be a string. This change appears to introduce a bug where errorMessage.fullMessage is accessed instead of using errorMessage directly.

Suggested change
fullMessage: `${errorMessage.fullMessage}\n${getErrorMessage(e)}`,
fullMessage: `${errorMessage}\n${getErrorMessage(e)}`,

Copilot uses AI. Check for mistakes.

},
);
}
Expand Down
4 changes: 3 additions & 1 deletion extensions/ql-vscode/src/local-queries/results-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,9 @@ export class ResultsView extends AbstractWebview<
}
const resultLocation = tryResolveLocation(sarifLoc, databaseItem);
if (!resultLocation) {
void this.logger.log(`Sarif location was not resolvable ${sarifLoc}`);
void this.logger.log(
`Sarif location was not resolvable: ${sarifLoc.uri.toString()}`,
);
continue;
}
const parsedMessage = parseSarifPlainTextMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class EvalLogDataProvider
? TreeItemCollapsibleState.Collapsed
: TreeItemCollapsibleState.None;
const treeItem = new TreeItem(element.label || "", state);
treeItem.tooltip = `${treeItem.label} || ''}`;
treeItem.tooltip =
typeof treeItem.label === "string"
? treeItem.label
: (treeItem.label?.label ?? "");
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original line 47 uses element.label || "" but the tooltip logic assumes treeItem.label could be non-string. This creates an inconsistency - if element.label is falsy, treeItem.label becomes an empty string, making the type check unnecessary. Either use element.label directly in the tooltip or handle the falsy case consistently.

Suggested change
: (treeItem.label?.label ?? "");
treeItem.tooltip = element.label || "";

Copilot uses AI. Check for mistakes.

return treeItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ async function scrubQueries(
throw new Error(EOL + errors.join(EOL));
}
} catch (e) {
void extLogger.log(`Error while scrubbing queries: ${e}`);
void extLogger.log(
`Error while scrubbing queries: ${getErrorMessage(e)}`,
);
} finally {
void extLogger.log(`Scrubbed ${scrubCount} old queries.`);
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/query-testing/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class TestRunner extends DisposableObject {
// So we need to display the error message ourselves and then rethrow.
void showAndLogWarningMessage(
extLogger,
`Cannot reopen database ${uri}: ${e}`,
`Cannot reopen database ${uri.toString()}: ${getErrorMessage(e)}`,
);
throw e;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/run-queries-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class QueryEvaluationInfo extends QueryOutputDir {
.map((v, i) => {
if (chunk.columns[i].kind === "String") {
return `"${
typeof v === "string" ? v.replaceAll('"', '""') : v
typeof v === "string" ? v.replaceAll('"', '""') : v.toString()
}"`;
} else if (chunk.columns[i].kind === "Entity") {
return (v as BqrsEntityValue).label;
Expand Down
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/status-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class CodeQlStatusBarHandler extends DisposableObject {
this.item.text = `CodeQL${canary}`;

const version = await this.cli.getVersion();
this.item.text = `CodeQL CLI v${version}${canary}`;
this.item.text = `CodeQL CLI v${version.toString()}${canary}`;
this.item.show();
}
}
3 changes: 2 additions & 1 deletion extensions/ql-vscode/src/tmp-dir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { dirSync } from "tmp-promise";
import { extLogger } from "./common/logging/vscode";
import { getErrorMessage } from "./common/helpers-pure";

// Shared temporary folder for the extension.
export const tmpDir = dirSync({
Expand All @@ -14,7 +15,7 @@ export const tmpDirDisposal = {
tmpDir.removeCallback();
} catch (e) {
void extLogger.log(
`Failed to remove temporary directory ${tmpDir.name}: ${e}`,
`Failed to remove temporary directory ${tmpDir.name}: ${getErrorMessage(e)}`,
);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export async function createGist(
});
if (response.status >= 300) {
throw new Error(
`Error exporting variant analysis results: ${response.status} ${
response?.data || ""
}`,
`Error exporting variant analysis results: ${response.status} ${JSON.stringify(
response?.data,
)}`,
);
}
return response.data.html_url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
ResultSeverity,
ThreadFlow,
} from "./shared/analysis-result";
import { getErrorMessage } from "../common/helpers-pure";

// A line of more than 8k characters is probably generated.
const CODE_SNIPPET_LARGE_LINE_SIZE_LIMIT = 8192;
Expand All @@ -47,7 +48,9 @@ export function extractAnalysisAlerts(
try {
alerts.push(...extractResultAlerts(run, result, fileLinkPrefix));
} catch (e) {
errors.push(`Error when processing SARIF result: ${e}`);
errors.push(
`Error when processing SARIF result: ${getErrorMessage(e)}`,
);
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class VariantAnalysisManager
): Promise<number | undefined> {
if (!isVariantAnalysisEnabledForGitHubHost()) {
throw new Error(
`Multi-repository variant analysis is not enabled for ${getEnterpriseUri()}`,
`Multi-repository variant analysis is not enabled for ${getEnterpriseUri()?.toString()}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,9 @@ function execAutofix(
try {
const cwd = options?.cwd || process.cwd();
if (showCommand) {
void extLogger.log(`Spawning '${bin} ${args.join(" ")}' in ${cwd}`);
void extLogger.log(
`Spawning '${bin} ${args.join(" ")}' in ${cwd.toString()}`,
);
}

let stdoutBuffer = "";
Expand Down
Loading
Loading