Carry a redacted stderr excerpt on git command failures#4467
Carry a redacted stderr excerpt on git command failures#4467yashranaway wants to merge 2 commits into
Conversation
Failed git commands recorded only stderrLength, so every precondition failure (branch exists, stale worktree metadata, permissions) collapsed into the same opaque message and diagnosing required rerunning git by hand. GitCommandError now carries a bounded stderrExcerpt for in-process consumers. Argument values are redacted from the excerpt and it stays out of the error schema and message, so nothing new reaches RPC clients, client events, or telemetry. Fixes pingdotgg#4380
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The length floor that keeps subcommand names readable also discarded extracted option values shorter than four characters, so a short secret in --option=value form could survive into the excerpt when stderr echoed only the value. Apply the floor to whole arguments only and redact extracted values at any length.
ApprovabilityVerdict: Approved This PR adds internal-only debugging info to Git command errors. The stderr excerpt is explicitly excluded from serialization (never reaches clients/telemetry), argument values are redacted to protect secrets, and comprehensive tests verify these security properties. You can customize Macroscope's approvability policy. Learn more. |
What Changed
GitCommandErrorgains an optionalstderrExcerptcarrying up to 400 characters of git's stderr, with command arguments and--option=valuevalues redacted out first. The excerpt lives outside the error schema and outsidemessage, so it is only visible to in-process consumers.Why
Failed git commands recorded only
stderrLength, so every precondition failure (branch already exists, stale worktree metadata, permissions, missing ref) collapsed into the same opaque "Git command exited with a non-zero status." and diagnosing meant rerunning the command by hand.Dropping stderr from messages is clearly deliberate here: existing tests forbid stderr and argument content in
messageand in client-facing events. This change keeps all of those guarantees (the redaction test now also covers the excerpt, and a new test proves schema encoding excludes it) while giving server-side code a bounded signal to log or inspect. This is the fallback design suggested in the issue.Fixes #4380
Testing
vp test runon GitVcsDriverCore, GitVcsDriver, and GitManager suites passes (105/105), including three new tests: excerpt present on a real failure, excerpt capped and argument-redacted, excerpt absent from schema encoding and frommessagepnpm typecheckin apps/server and packages/contracts cleanvp linton changed files cleanChecklist
Note
Low Risk
Localized to git error construction and redaction; preserves existing guarantees that stderr and secrets do not appear in messages or RPC-encoded errors.
Overview
Adds an optional
stderrExcerptonGitCommandErrorso server-side code can see a short, redacted slice of git stderr when a command fails, without changing client-facingmessageor serialized error payloads.attachGitStderrExcerptinGitVcsDriverCorebuilds that excerpt: it redacts whole args (length ≥ 4) and--option=valuevalues (any length), normalizes whitespace, caps at 400 characters, and attaches it only on the error instance. Both non-zero exit paths (executeRawandexecuteGit) now run failures through this helper.The field is declared on the class in
packages/contractsbut outside the Schema, so schema encoding still omits it. Tests cover real failures, redaction/capping, and that excerpts stay out ofmessageand encoded errors.Reviewed by Cursor Bugbot for commit 216d1b3. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Carry a redacted stderr excerpt on
GitCommandErrorfor in-process consumersstderrExcerptfield toGitCommandErrorin git.ts; the field is intentionally excluded from the schema and error message so it never leaks to external consumers.attachGitStderrExcerptin GitVcsDriverCore.ts, which redacts argument values (above a 4-char minimum) and--option=valuepairs from stderr, collapses whitespace, and caps the excerpt at 400 characters.runGitCommandandexecuteGitWithStableDiagnosticsnow attach the excerpt to non-zero exit errors.Macroscope summarized 216d1b3.