-
Notifications
You must be signed in to change notification settings - Fork 43
feat: collect VS Code diagnostics in support bundles #971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
db36fd0
feat: collect VS Code diagnostics in support bundles
EhabY f7c23b0
refactor(supportBundle): harden log/settings collection and simplify
EhabY e907191
refactor(supportBundle): address PR #971 review feedback
EhabY 162b611
refactor(supportBundle): share Remote-SSH layout predicates
EhabY 7e8a79d
fix(supportBundle): cap log size and stop redacting defaults
EhabY 5ab97dc
refactor(supportBundle): narrow settings redaction and tidy modules
EhabY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| 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/fs"; | ||
|
|
||
| import { collectVsCodeDiagnostics, type LogSources } from "./logFiles"; | ||
|
|
||
| export type { LogSources } from "./logFiles"; | ||
|
|
||
| const unzipAsync = promisify(unzip); | ||
| const zipAsync = promisify(zip); | ||
|
|
||
| /** | ||
| * Best-effort: append VS Code logs to the bundle zip, swapped in by atomic | ||
| * rename so a failure leaves the original intact. | ||
| */ | ||
| export async function appendVsCodeLogs( | ||
| zipPath: string, | ||
| sources: LogSources, | ||
| logger: Logger, | ||
| ): Promise<void> { | ||
| try { | ||
| const diagnosticFiles = await collectVsCodeDiagnostics(sources, logger); | ||
| if (diagnosticFiles.size === 0) { | ||
| logger.info("No VS Code diagnostics found to add to support bundle"); | ||
| return; | ||
| } | ||
|
|
||
| logger.info( | ||
| `Adding ${diagnosticFiles.size} VS Code diagnostic file(s) to support bundle`, | ||
| ); | ||
|
|
||
| const outputBundlePath = vscodeBundlePath(zipPath); | ||
| try { | ||
| await writeBundleWithDiagnostics( | ||
| zipPath, | ||
| outputBundlePath, | ||
| diagnosticFiles, | ||
| ); | ||
| } catch (error) { | ||
| logger.error( | ||
| "Failed to add VS Code diagnostics to support bundle", | ||
| error, | ||
| ); | ||
|
|
||
| // Write-failure path only: success and failed-rename both keep the file. | ||
| try { | ||
| await fs.rm(outputBundlePath, { force: true }); | ||
| } catch (cleanupError) { | ||
| logger.warn( | ||
| `Could not clean up partial bundle at ${outputBundlePath}`, | ||
| cleanupError, | ||
| ); | ||
| } | ||
|
EhabY marked this conversation as resolved.
|
||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await renameWithRetry(fs.rename, outputBundlePath, zipPath); | ||
| } catch (error) { | ||
| logger.warn( | ||
| `Could not replace original bundle; VS Code diagnostics 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 diagnostics", error); | ||
| } | ||
| } | ||
|
|
||
| function vscodeBundlePath(zipPath: string): string { | ||
| const parsed = path.parse(zipPath); | ||
| return path.join( | ||
| parsed.dir, | ||
| `${parsed.name}-vscode-${randomUUID().slice(0, 8)}${parsed.ext}`, | ||
| ); | ||
| } | ||
|
|
||
| async function writeBundleWithDiagnostics( | ||
| zipPath: string, | ||
| outputPath: string, | ||
| diagnosticFiles: 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 diagnosticFiles) { | ||
| entries[name] = data; | ||
| } | ||
|
|
||
| // Set mode at create time: avoids a umask window and a fallible chmod. | ||
| await fs.writeFile(outputPath, await zipAsync(entries), { mode: sourceMode }); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.