Skip to content

Commit b852302

Browse files
takecyclaude
andcommitted
fix(printer): emit error and repo-list messages on stderr
PrintMsgErr and PrintRepoErr were writing to p.writer (stdout) despite their names and despite the parallel Error method routing its output to p.errWriter. That meant the gih CLI's error notices ("Failed: <repo>", "Timeout: <repo>") and the final failed/timed-out repository list landed on stdout — indistinguishable from successful results when the caller used `2>` to capture errors or `>` to capture results. Switch both methods to p.errWriter to match the Error method and the implicit contract suggested by the *Err naming. Existing tests use NewPrinter(&buf, &buf) so they keep passing; the new behaviour shows up only when callers wire distinct writers, which is the use case this fix enables. Reported by GitHub Copilot on PR #26. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4ea80be commit b852302

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

printer/print.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,27 +114,29 @@ func (p *Printer) PrintMsg(msg string) {
114114
}
115115
}
116116

117-
// PrintMsgErr prints error message
117+
// PrintMsgErr prints an error message to errWriter so that callers can
118+
// redirect stderr separately from stdout (consistent with Printer.Error).
118119
func (p *Printer) PrintMsgErr(msg string) {
119120
type message struct {
120121
Msg string
121122
}
122123
p.mu.Lock()
123124
defer p.mu.Unlock()
124-
if err := msgErrTpl.Execute(p.writer, message{Msg: msg}); err != nil {
125+
if err := msgErrTpl.Execute(p.errWriter, message{Msg: msg}); err != nil {
125126
log.Println(err)
126127
}
127128
}
128129

129-
// PrintRepoErr prints error message
130+
// PrintRepoErr prints a header plus a list of repository paths to errWriter
131+
// (matching the stderr semantics of PrintMsgErr / Error).
130132
func (p *Printer) PrintRepoErr(msg string, repos []string) {
131133
type message struct {
132134
Msg string
133135
Repos []string
134136
}
135137
p.mu.Lock()
136138
defer p.mu.Unlock()
137-
if err := repoErrTpl.Execute(p.writer, message{Msg: msg, Repos: repos}); err != nil {
139+
if err := repoErrTpl.Execute(p.errWriter, message{Msg: msg, Repos: repos}); err != nil {
138140
log.Println(err)
139141
}
140142
}

0 commit comments

Comments
 (0)