Skip to content

Commit 60d22dc

Browse files
committed
Only log sync error when != nil
1 parent e4803b1 commit 60d22dc

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

internal/syncwriter/syncwriter.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,20 @@ func (w *Writer) Sync(sinkName string) {
5555
return
5656
}
5757
err := s.Sync()
58-
if _, ok := w.w.(*os.File); ok {
59-
// Opened files do not necessarily support syncing.
60-
// E.g. stdout and stderr both do not so we need
61-
// to ignore these errors.
62-
// See https://github.com/uber-go/zap/issues/370
63-
// See https://github.com/cdr/slog/pull/43
64-
if errorsIsAny(err, syscall.EINVAL, syscall.ENOTTY, syscall.EBADF) {
65-
return
58+
if err != nil {
59+
if _, ok := w.w.(*os.File); ok {
60+
// Opened files do not necessarily support syncing.
61+
// E.g. stdout and stderr both do not so we need
62+
// to ignore these errors.
63+
// See https://github.com/uber-go/zap/issues/370
64+
// See https://github.com/cdr/slog/pull/43
65+
if errorsIsAny(err, syscall.EINVAL, syscall.ENOTTY, syscall.EBADF) {
66+
return
67+
}
6668
}
67-
}
6869

69-
w.errorf("failed to sync %v: %+v", sinkName, err)
70+
w.errorf("failed to sync %v: %+v", sinkName, err)
71+
}
7072
}
7173

7274
func errorsIsAny(err error, errs ...error) bool {

0 commit comments

Comments
 (0)