Skip to content

fix: use correct error variable in stderr copy check#892

Open
toller892 wants to merge 1 commit into
charmbracelet:mainfrom
toller892:fix/stderr-error-check
Open

fix: use correct error variable in stderr copy check#892
toller892 wants to merge 1 commit into
charmbracelet:mainfrom
toller892:fix/stderr-error-check

Conversation

@toller892
Copy link
Copy Markdown

Problem

In gitServiceHandler (pkg/git/service.go), the stderr io.Copy goroutine checks the wrong error variable:

if _, erro := io.Copy(scmd.Stderr, stderr); err != nil {  // checks 'err', not 'erro'
    log.Errorf("gitServiceHandler: failed to copy stderr: %v", erro)
}

The condition uses err (from the outer scope — set by StdinPipe/StdoutPipe/StderrPipe calls) instead of erro (the actual error from io.Copy).

Effect:

  • When err is nil (normal case): stderr copy errors are silently swallowed — the condition is false and the error is never logged.
  • When err is non-nil (pipe creation failed): the condition is always true, but erro is nil so the log message prints <nil> instead of the actual error.

Fix

Change err != nil to erro != nil on line 150:

if _, erro := io.Copy(scmd.Stderr, stderr); erro != nil {

This is a single-character fix that ensures stderr copy failures are properly detected and logged.

Testing

  • go build ./pkg/git/... — passes
  • go test ./pkg/git/... — passes (1.781s)
  • go vet ./pkg/git/... — clean

In gitServiceHandler, the stderr io.Copy goroutine checked the outer
scope variable 'err' instead of the local 'erro' from the copy
operation. This caused stderr copy errors to be silently swallowed
when the outer err was nil, and incorrectly triggered when the outer
err was non-nil.

Change the condition from 'err != nil' to 'erro != nil' to properly
detect and log stderr copy failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant