-
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
Open
EhabY
wants to merge
5
commits into
main
Choose a base branch
from
feat/support-bundle-diagnostics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 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 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); | ||
|
|
||
| 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: no umask window, no separate chmod that | ||
| // could fail on filesystems that don't honor mode bits. | ||
| await fs.writeFile(outputPath, await zipAsync(entries), { mode: 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 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, | ||
| ); | ||
|
|
||
| try { | ||
| await fs.rm(outputBundlePath, { force: true }); | ||
| } catch (cleanupError) { | ||
| logger.warn( | ||
| `Could not clean up partial bundle at ${outputBundlePath}`, | ||
| cleanupError, | ||
| ); | ||
| } | ||
|
Comment on lines
+75
to
+82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Cleanup sounds to me like "finally" step. |
||
| 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); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we append ".incomplete" or something to indicate that the artifact is pending renaming?