improve fprintf related error handling

This commit is contained in:
Michael Eischer
2024-11-01 17:07:43 +01:00
parent 41fa41b28b
commit 569a117a1d
10 changed files with 43 additions and 33 deletions
+1 -1
View File
@@ -106,7 +106,7 @@ func runRESTServer(ctx context.Context, t testing.TB, dir, reqListenAddr string)
matched = true
}
}
fmt.Fprintln(os.Stdout, line) // print all output to console
_, _ = fmt.Fprintln(os.Stdout, line) // print all output to console
}
}()
+1 -1
View File
@@ -120,7 +120,7 @@ func goroutineNum() int {
runtime.Stack(b, false)
var num int
fmt.Sscanf(string(b), "goroutine %d ", &num)
_, _ = fmt.Sscanf(string(b), "goroutine %d ", &num)
return num
}
+1 -1
View File
@@ -42,7 +42,7 @@ func (rd *eofDetectReader) Close() error {
msg += fmt.Sprintf(", body: %q", buf)
}
fmt.Fprintln(os.Stderr, msg)
_, _ = fmt.Fprintln(os.Stderr, msg)
Log("%s: %+v", msg, errors.New("Close()"))
}
return rd.rd.Close()
+6 -4
View File
@@ -212,7 +212,7 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
}
if _, err := io.WriteString(dst, msg.line); err != nil {
fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
}
if flush == nil {
@@ -220,16 +220,18 @@ func (t *Terminal) runWithoutStatus(ctx context.Context) {
}
if err := flush(); err != nil {
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
}
case stat := <-t.status:
for _, line := range stat.lines {
// Ensure that each message ends with exactly one newline.
fmt.Fprintln(t.wr, strings.TrimRight(line, "\n"))
if _, err := fmt.Fprintln(t.wr, strings.TrimRight(line, "\n")); err != nil {
_, _ = fmt.Fprintf(os.Stderr, "write failed: %v\n", err)
}
}
if err := t.wr.Flush(); err != nil {
fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "flush failed: %v\n", err)
}
}
}