From e3041740e4d3b9cd9eda17a737e9e99102f24331 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Tue, 14 Nov 2023 19:04:30 +0100 Subject: [PATCH] tsdb/fileutil: use Go standard errors Signed-off-by: Matthieu MOREL --- tsdb/fileutil/mmap.go | 9 ++++----- tsdb/fileutil/preallocate_linux.go | 9 +++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tsdb/fileutil/mmap.go b/tsdb/fileutil/mmap.go index 4dbca4f97..782ff27ec 100644 --- a/tsdb/fileutil/mmap.go +++ b/tsdb/fileutil/mmap.go @@ -14,9 +14,8 @@ package fileutil import ( + "fmt" "os" - - "github.com/pkg/errors" ) type MmapFile struct { @@ -31,7 +30,7 @@ func OpenMmapFile(path string) (*MmapFile, error) { func OpenMmapFileWithSize(path string, size int) (mf *MmapFile, retErr error) { f, err := os.Open(path) if err != nil { - return nil, errors.Wrap(err, "try lock file") + return nil, fmt.Errorf("try lock file: %w", err) } defer func() { if retErr != nil { @@ -41,14 +40,14 @@ func OpenMmapFileWithSize(path string, size int) (mf *MmapFile, retErr error) { if size <= 0 { info, err := f.Stat() if err != nil { - return nil, errors.Wrap(err, "stat") + return nil, fmt.Errorf("stat: %w", err) } size = int(info.Size()) } b, err := mmap(f, size) if err != nil { - return nil, errors.Wrapf(err, "mmap, size %d", size) + return nil, fmt.Errorf("mmap, size %d: %w", size, err) } return &MmapFile{f: f, b: b}, nil diff --git a/tsdb/fileutil/preallocate_linux.go b/tsdb/fileutil/preallocate_linux.go index ada046221..026c69b35 100644 --- a/tsdb/fileutil/preallocate_linux.go +++ b/tsdb/fileutil/preallocate_linux.go @@ -15,6 +15,7 @@ package fileutil import ( + "errors" "os" "syscall" ) @@ -23,10 +24,10 @@ func preallocExtend(f *os.File, sizeInBytes int64) error { // use mode = 0 to change size err := syscall.Fallocate(int(f.Fd()), 0, 0, sizeInBytes) if err != nil { - errno, ok := err.(syscall.Errno) + var errno syscall.Errno // not supported; fallback // fallocate EINTRs frequently in some environments; fallback - if ok && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { + if errors.As(err, &errno) && (errno == syscall.ENOTSUP || errno == syscall.EINTR) { return preallocExtendTrunc(f, sizeInBytes) } } @@ -37,9 +38,9 @@ func preallocFixed(f *os.File, sizeInBytes int64) error { // use mode = 1 to keep size; see FALLOC_FL_KEEP_SIZE err := syscall.Fallocate(int(f.Fd()), 1, 0, sizeInBytes) if err != nil { - errno, ok := err.(syscall.Errno) + var errno syscall.Errno // treat not supported as nil error - if ok && errno == syscall.ENOTSUP { + if errors.As(err, &errno) && errno == syscall.ENOTSUP { return nil } }