diff --git a/extensions/ql-vscode/eslint.config.mjs b/extensions/ql-vscode/eslint.config.mjs index 9496fb03876..e453a1f9838 100644 --- a/extensions/ql-vscode/eslint.config.mjs +++ b/extensions/ql-vscode/eslint.config.mjs @@ -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", diff --git a/extensions/ql-vscode/src/codeql-cli/cli.ts b/extensions/ql-vscode/src/codeql-cli/cli.ts index 2074f0d7dec..27a61c4a143 100644 --- a/extensions/ql-vscode/src/codeql-cli/cli.ts +++ b/extensions/ql-vscode/src/codeql-cli/cli.ts @@ -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."); } @@ -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}`, ), ); } diff --git a/extensions/ql-vscode/src/codeql-cli/distribution.ts b/extensions/ql-vscode/src/codeql-cli/distribution.ts index ba3050ca904..35bbb7acf16 100644 --- a/extensions/ql-vscode/src/codeql-cli/distribution.ts +++ b/extensions/ql-vscode/src/codeql-cli/distribution.ts @@ -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)}.`, ); } } @@ -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)}.`, ); } diff --git a/extensions/ql-vscode/src/codeql-cli/query-language.ts b/extensions/ql-vscode/src/codeql-cli/query-language.ts index 17430ee06a5..d5cef76e697 100644 --- a/extensions/ql-vscode/src/codeql-cli/query-language.ts +++ b/extensions/ql-vscode/src/codeql-cli/query-language.ts @@ -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.`, ); diff --git a/extensions/ql-vscode/src/codeql-cli/query-metadata.ts b/extensions/ql-vscode/src/codeql-cli/query-metadata.ts index 0991bf952d3..88fe52d49ba 100644 --- a/extensions/ql-vscode/src/codeql-cli/query-metadata.ts +++ b/extensions/ql-vscode/src/codeql-cli/query-metadata.ts @@ -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. @@ -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; } } diff --git a/extensions/ql-vscode/src/common/short-paths.ts b/extensions/ql-vscode/src/common/short-paths.ts index 0025b96da05..860544c38d4 100644 --- a/extensions/ql-vscode/src/common/short-paths.ts +++ b/extensions/ql-vscode/src/common/short-paths.ts @@ -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; } diff --git a/extensions/ql-vscode/src/common/vscode/archive-filesystem-provider.ts b/extensions/ql-vscode/src/common/vscode/archive-filesystem-provider.ts index c82225f42f1..1ee61468c36 100644 --- a/extensions/ql-vscode/src/common/vscode/archive-filesystem-provider.ts +++ b/extensions/ql-vscode/src/common/vscode/archive-filesystem-provider.ts @@ -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).`, ); } } diff --git a/extensions/ql-vscode/src/common/vscode/webview-html.ts b/extensions/ql-vscode/src/common/vscode/webview-html.ts index 9a02714f726..e1eac40024c 100644 --- a/extensions/ql-vscode/src/common/vscode/webview-html.ts +++ b/extensions/ql-vscode/src/common/vscode/webview-html.ts @@ -89,7 +89,7 @@ export function getHtmlForWebview(
- `; @@ -101,9 +101,9 @@ function getNonce(): string { } function createStylesLinkWithNonce(nonce: string, uri: Uri): string { - return ``; + return ``; } function createStylesLinkWithoutNonce(uri: Uri): string { - return ``; + return ``; } diff --git a/extensions/ql-vscode/src/databases/local-databases-ui.ts b/extensions/ql-vscode/src/databases/local-databases-ui.ts index d1ed2147fe7..823093bfe49 100644 --- a/extensions/ql-vscode/src/databases/local-databases-ui.ts +++ b/extensions/ql-vscode/src/databases/local-databases-ui.ts @@ -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); @@ -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, diff --git a/extensions/ql-vscode/src/databases/local-databases/database-manager.ts b/extensions/ql-vscode/src/databases/local-databases/database-manager.ts index 643c601cd3e..5685f5f997a 100644 --- a/extensions/ql-vscode/src/databases/local-databases/database-manager.ts +++ b/extensions/ql-vscode/src/databases/local-databases/database-manager.ts @@ -64,12 +64,13 @@ const DB_LIST = "databaseList"; */ function eventFired( event: vscode.Event, + eventName: string, timeoutMs = 1000, ): Promise { 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(); @@ -256,7 +257,7 @@ export class DatabaseManager extends DisposableObject { private async reimportTestDatabase(databaseUri: vscode.Uri): Promise { 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); @@ -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", + ); } } @@ -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)}.`, ); } } diff --git a/extensions/ql-vscode/src/extension.ts b/extensions/ql-vscode/src/extension.ts index 3edd7b8944f..bd73929ad63 100644 --- a/extensions/ql-vscode/src/extension.ts +++ b/extensions/ql-vscode/src/extension.ts @@ -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); }, @@ -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; @@ -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; } @@ -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()}.` ); } })(); diff --git a/extensions/ql-vscode/src/language-support/ast-viewer/ast-viewer.ts b/extensions/ql-vscode/src/language-support/ast-viewer/ast-viewer.ts index 71c057aa62c..f186674c08e 100644 --- a/extensions/ql-vscode/src/language-support/ast-viewer/ast-viewer.ts +++ b/extensions/ql-vscode/src/language-support/ast-viewer/ast-viewer.ts @@ -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 ?? "")}`; treeItem.command = { command: "codeQLAstViewer.gotoCode", title: "Go To Code", - tooltip: `Go To ${item.location}`, + tooltip: "Go To Code", arguments: [item], }; return treeItem; diff --git a/extensions/ql-vscode/src/language-support/query-editor.ts b/extensions/ql-vscode/src/language-support/query-editor.ts index 71e66900037..a7567e1f1be 100644 --- a/extensions/ql-vscode/src/language-support/query-editor.ts +++ b/extensions/ql-vscode/src/language-support/query-editor.ts @@ -99,7 +99,7 @@ async function previewQueryHelp( telemetryListener, errorMessage, { - fullMessage: `${errorMessage}\n${getErrorMessage(e)}`, + fullMessage: `${errorMessage.fullMessage}\n${getErrorMessage(e)}`, }, ); } diff --git a/extensions/ql-vscode/src/local-queries/results-view.ts b/extensions/ql-vscode/src/local-queries/results-view.ts index 00eae1138aa..55480c344f8 100644 --- a/extensions/ql-vscode/src/local-queries/results-view.ts +++ b/extensions/ql-vscode/src/local-queries/results-view.ts @@ -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); diff --git a/extensions/ql-vscode/src/query-evaluation-logging/eval-log-viewer.ts b/extensions/ql-vscode/src/query-evaluation-logging/eval-log-viewer.ts index a35b1cd72c4..0bd7a572b44 100644 --- a/extensions/ql-vscode/src/query-evaluation-logging/eval-log-viewer.ts +++ b/extensions/ql-vscode/src/query-evaluation-logging/eval-log-viewer.ts @@ -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 ?? ""); return treeItem; } diff --git a/extensions/ql-vscode/src/query-history/query-history-scrubber.ts b/extensions/ql-vscode/src/query-history/query-history-scrubber.ts index 961124116b6..1e31ccdf300 100644 --- a/extensions/ql-vscode/src/query-history/query-history-scrubber.ts +++ b/extensions/ql-vscode/src/query-history/query-history-scrubber.ts @@ -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.`); } diff --git a/extensions/ql-vscode/src/query-testing/test-runner.ts b/extensions/ql-vscode/src/query-testing/test-runner.ts index f0d8aaa39e0..8c38fca4ab6 100644 --- a/extensions/ql-vscode/src/query-testing/test-runner.ts +++ b/extensions/ql-vscode/src/query-testing/test-runner.ts @@ -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; } diff --git a/extensions/ql-vscode/src/run-queries-shared.ts b/extensions/ql-vscode/src/run-queries-shared.ts index 4e463812cb0..03e25df46dc 100644 --- a/extensions/ql-vscode/src/run-queries-shared.ts +++ b/extensions/ql-vscode/src/run-queries-shared.ts @@ -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; diff --git a/extensions/ql-vscode/src/status-bar.ts b/extensions/ql-vscode/src/status-bar.ts index 4dd9f2523c2..66b7d2270c3 100644 --- a/extensions/ql-vscode/src/status-bar.ts +++ b/extensions/ql-vscode/src/status-bar.ts @@ -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(); } } diff --git a/extensions/ql-vscode/src/tmp-dir.ts b/extensions/ql-vscode/src/tmp-dir.ts index b556150a0df..51b1cc814ec 100644 --- a/extensions/ql-vscode/src/tmp-dir.ts +++ b/extensions/ql-vscode/src/tmp-dir.ts @@ -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({ @@ -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)}`, ); } }, diff --git a/extensions/ql-vscode/src/variant-analysis/gh-api/gh-api-client.ts b/extensions/ql-vscode/src/variant-analysis/gh-api/gh-api-client.ts index 24abc989a4b..be8d323c7c4 100644 --- a/extensions/ql-vscode/src/variant-analysis/gh-api/gh-api-client.ts +++ b/extensions/ql-vscode/src/variant-analysis/gh-api/gh-api-client.ts @@ -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; diff --git a/extensions/ql-vscode/src/variant-analysis/sarif-processing.ts b/extensions/ql-vscode/src/variant-analysis/sarif-processing.ts index 728fc90d41f..f998f228e19 100644 --- a/extensions/ql-vscode/src/variant-analysis/sarif-processing.ts +++ b/extensions/ql-vscode/src/variant-analysis/sarif-processing.ts @@ -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; @@ -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; } } diff --git a/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts b/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts index 9bb707a9775..4256d037cfc 100644 --- a/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts +++ b/extensions/ql-vscode/src/variant-analysis/variant-analysis-manager.ts @@ -332,7 +332,7 @@ export class VariantAnalysisManager ): Promise { if (!isVariantAnalysisEnabledForGitHubHost()) { throw new Error( - `Multi-repository variant analysis is not enabled for ${getEnterpriseUri()}`, + `Multi-repository variant analysis is not enabled for ${getEnterpriseUri()?.toString()}`, ); } diff --git a/extensions/ql-vscode/src/variant-analysis/view-autofixes.ts b/extensions/ql-vscode/src/variant-analysis/view-autofixes.ts index 16bbac07bd8..0d0214b07cf 100644 --- a/extensions/ql-vscode/src/variant-analysis/view-autofixes.ts +++ b/extensions/ql-vscode/src/variant-analysis/view-autofixes.ts @@ -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 = ""; diff --git a/extensions/ql-vscode/test/vscode-tests/jest.activated-extension.setup.ts b/extensions/ql-vscode/test/vscode-tests/jest.activated-extension.setup.ts index 5085fc19460..dc47c409111 100644 --- a/extensions/ql-vscode/test/vscode-tests/jest.activated-extension.setup.ts +++ b/extensions/ql-vscode/test/vscode-tests/jest.activated-extension.setup.ts @@ -8,6 +8,7 @@ import { setStoragePath, storagePath, } from "./global.helper"; +import { getErrorMessage } from "../../src/common/helpers-pure"; if (process.env.CI) { jest.retryTimes(3, { @@ -50,6 +51,8 @@ export async function afterAllAction() { } catch (e) { // we are exiting anyway so don't worry about it. // most likely the directory this is a test on Windows and some files are locked. - console.warn(`Failed to remove storage directory '${storagePath}': ${e}`); + console.warn( + `Failed to remove storage directory '${storagePath}': ${getErrorMessage(e)}`, + ); } }