Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
workspaceStatusLabel,
} from "./api/api-helper";
import * as cliExec from "./core/cliExec";
import { appendVsCodeLogs } from "./core/supportBundleLogs";
import { CertificateError } from "./error/certificateError";
import { toError } from "./error/errorUtils";
import { type FeatureSet, featureSetForVersion } from "./featureSet";
Expand All @@ -26,6 +25,7 @@ import {
applySettingOverrides,
} from "./remote/sshOverrides";
import { resolveCliAuth } from "./settings/cli";
import { appendVsCodeLogs } from "./supportBundle/appendVsCodeLogs";
import { toRemoteAuthority, toSafeHost } from "./util";
import { vscodeProposed } from "./vscodeProposed";
import { parseSpeedtestResult } from "./webviews/speedtest/types";
Expand Down Expand Up @@ -304,7 +304,7 @@ export class Commands {
await appendVsCodeLogs(
outputUri.fsPath,
{
remoteSshLogPath: this.workspaceLogPath,
activeProxyLogPath: this.workspaceLogPath,
proxyLogDir: this.pathResolver.getProxyLogPath(),
extensionLogDir: this.pathResolver.getCodeLogDir(),
},
Expand Down
158 changes: 0 additions & 158 deletions src/core/supportBundleLogs.ts

This file was deleted.

90 changes: 90 additions & 0 deletions src/supportBundle/appendVsCodeLogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { unzip, zip, type Zippable } from "fflate";
import { randomUUID } from "node:crypto";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";

import { type Logger } from "../logging/logger";
import { renameWithRetry } from "../util";

import { collectVsCodeDiagnostics, type LogSources } from "./diagnostics";

export type { LogSources } from "./diagnostics";

const unzipAsync = promisify(unzip);
const zipAsync = promisify(zip);

function vscodeBundlePath(zipPath: string): string {
const parsed = path.parse(zipPath);
return path.join(
parsed.dir,
`${parsed.name}-vscode-${randomUUID()}${parsed.ext}`,
);
}

async function writeBundleWithLogs(
zipPath: string,
outputPath: string,
logFiles: Map<string, Uint8Array>,
): Promise<void> {
const sourceMode = (await fs.stat(zipPath)).mode & 0o777;
const entries: Zippable = await unzipAsync(await fs.readFile(zipPath));

for (const [name, data] of logFiles) {
entries[name] = data;
}

await fs.writeFile(outputPath, await zipAsync(entries));
await fs.chmod(outputPath, sourceMode);
}

/**
* Best-effort: append VS Code logs to a support bundle zip.
* Uses atomic rename to avoid corrupting the original bundle on failure.
*/
export async function appendVsCodeLogs(
zipPath: string,
sources: LogSources,
logger: Logger,
): Promise<void> {
try {
const logFiles = await collectVsCodeDiagnostics(sources, logger);
if (logFiles.size === 0) {
logger.info("No VS Code logs found to add to support bundle");
return;
}

logger.info(
`Adding ${logFiles.size} VS Code log file(s) to support bundle`,
);

const outputBundlePath = vscodeBundlePath(zipPath);
try {
await writeBundleWithLogs(zipPath, outputBundlePath, logFiles);
} catch (error) {
logger.error("Failed to add VS Code logs to support bundle", error);

try {
await fs.rm(outputBundlePath, { force: true });
} catch (cleanupError) {
logger.warn(
`Could not clean up partial bundle at ${outputBundlePath}`,
cleanupError,
);
}
return;
}

try {
await renameWithRetry(fs.rename, outputBundlePath, zipPath);
} catch (error) {
logger.warn(
`Could not replace original bundle; VS Code logs saved separately at ${outputBundlePath}`,
error,
);
}
} catch (error) {
// Best-effort: never let a failure here lose the user's bundle.
logger.error("Unexpected error appending VS Code logs", error);
}
}
18 changes: 18 additions & 0 deletions src/supportBundle/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type Logger } from "../logging/logger";

import { collectSupportLogFiles, type LogSources } from "./logFiles";
import { collectSettingsFile } from "./settings";

export type { LogSources } from "./logFiles";

export async function collectVsCodeDiagnostics(
sources: LogSources,
logger: Logger,
): Promise<Map<string, Uint8Array>> {
const files = await collectSupportLogFiles(sources, logger);
const settings = collectSettingsFile(logger);
if (settings) {
files.set("vscode-logs/settings.json", settings);
}
return files;
}
Loading
Loading