summaryrefslogtreecommitdiff
path: root/pkg/errorhandling/errorhandling.go
blob: 970d47636c6756de1b7df615a53ae762cfe3bd48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package errorhandling

import (
	"os"

	"github.com/sirupsen/logrus"
)

// SyncQuiet syncs a file and logs any error. Should only be used within
// a defer.
func SyncQuiet(f *os.File) {
	if err := f.Sync(); err != nil {
		logrus.Errorf("unable to sync file %s: %q", f.Name(), err)
	}
}

// CloseQuiet closes a file and logs any error. Should only be used within
// a defer.
func CloseQuiet(f *os.File) {
	if err := f.Close(); err != nil {
		logrus.Errorf("unable to close file %s: %q", f.Name(), err)
	}
}