chore(all): review error wrappings

- remove repetitive `cannot` and `failed` prefixes
- rename `unmarshaling` to `decoding`
This commit is contained in:
Quentin McGaw
2023-04-01 16:53:04 +00:00
parent 63a696d7e7
commit 4ba159e483
76 changed files with 178 additions and 178 deletions

View File

@@ -22,7 +22,7 @@ func (t *Tun) Check(path string) error {
info, err := f.Stat()
if err != nil {
return fmt.Errorf("cannot stat TUN file: %w", err)
return fmt.Errorf("getting stat information for TUN file: %w", err)
}
sys, ok := info.Sys().(*syscall.Stat_t)
@@ -37,7 +37,7 @@ func (t *Tun) Check(path string) error {
}
if err := f.Close(); err != nil {
return fmt.Errorf("cannot close TUN device: %w", err)
return fmt.Errorf("closing TUN device: %w", err)
}
return nil

View File

@@ -22,18 +22,18 @@ func (t *Tun) Create(path string) error {
dev := unix.Mkdev(major, minor)
err := t.mknod(path, unix.S_IFCHR, int(dev))
if err != nil {
return fmt.Errorf("cannot create TUN device file node: %w", err)
return fmt.Errorf("creating TUN device file node: %w", err)
}
fd, err := unix.Open(path, 0, 0)
if err != nil {
return fmt.Errorf("cannot Unix Open TUN device file: %w", err)
return fmt.Errorf("unix opening TUN device file: %w", err)
}
const nonBlocking = true
err = unix.SetNonblock(fd, nonBlocking)
if err != nil {
return fmt.Errorf("cannot set non block to TUN device file descriptor: %w", err)
return fmt.Errorf("setting non block to TUN device file descriptor: %w", err)
}
return nil

View File

@@ -40,7 +40,7 @@ func Test_Tun(t *testing.T) {
// Create TUN device fail as file exists
err = tun.Create(path)
require.Error(t, err)
require.Equal(t, "cannot create TUN device file node: file exists", err.Error())
require.EqualError(t, err, "creating TUN device file node: file exists")
// Remove simple file
err = os.Remove(path)