feat: replace github.com/pkg/errors to errors

Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
haoyun
2022-01-07 10:19:31 +08:00
parent 3ccd43c8f6
commit bbe46b8c43
299 changed files with 1896 additions and 1874 deletions

View File

@@ -17,13 +17,13 @@
package mount
import (
"errors"
"fmt"
"os"
"path"
"strings"
"time"
"github.com/pkg/errors"
exec "golang.org/x/sys/execabs"
"golang.org/x/sys/unix"
)
@@ -163,7 +163,7 @@ func unmount(target string, flags int) error {
}
return nil
}
return errors.Wrapf(unix.EBUSY, "failed to unmount target %s", target)
return fmt.Errorf("failed to unmount target %s: %w", target, unix.EBUSY)
}
// UnmountAll repeatedly unmounts the given mount point until there
@@ -365,19 +365,22 @@ func mountAt(chdir string, source, target, fstype string, flags uintptr, data st
f, err := os.Open(chdir)
if err != nil {
return errors.Wrap(err, "failed to mountat")
return fmt.Errorf("failed to mountat: %w", err)
}
defer f.Close()
fs, err := f.Stat()
if err != nil {
return errors.Wrap(err, "failed to mountat")
return fmt.Errorf("failed to mountat: %w", err)
}
if !fs.IsDir() {
return errors.Wrap(errors.Errorf("%s is not dir", chdir), "failed to mountat")
return fmt.Errorf("failed to mountat: %s is not dir", chdir)
}
return errors.Wrap(fMountat(f.Fd(), source, target, fstype, flags, data), "failed to mountat")
if err := fMountat(f.Fd(), source, target, fstype, flags, data); err != nil {
return fmt.Errorf("failed to mountat: %w", err)
}
return nil
}
func (m *Mount) mountWithHelper(helperBinary, typePrefix, target string) error {
@@ -406,7 +409,7 @@ func (m *Mount) mountWithHelper(helperBinary, typePrefix, target string) error {
return nil
}
if !errors.Is(err, unix.ECHILD) {
return errors.Wrapf(err, "mount helper [%s %v] failed: %q", helperBinary, args, string(out))
return fmt.Errorf("mount helper [%s %v] failed: %q: %w", helperBinary, args, string(out), err)
}
// We got ECHILD, we are not sure whether the mount was successful.
// If the mount ID has changed, we are sure we got some new mount, but still not sure it is fully completed.
@@ -419,5 +422,5 @@ func (m *Mount) mountWithHelper(helperBinary, typePrefix, target string) error {
_ = unmount(target, 0)
}
}
return errors.Errorf("mount helper [%s %v] failed with ECHILD (retired %d times)", helperBinary, args, retriesOnECHILD)
return fmt.Errorf("mount helper [%s %v] failed with ECHILD (retired %d times)", helperBinary, args, retriesOnECHILD)
}