all: Modernize error wrapping (#8491)

This replaces old style errors.Wrap with modern fmt.Errorf and removes
the (direct) dependency on github.com/pkg/errors. A couple of cases are
adjusted by hand as previously errors.Wrap(nil, ...) would return nil,
which is not what fmt.Errorf does.
This commit is contained in:
Jakob Borg
2022-08-16 10:01:49 +02:00
committed by GitHub
parent 75eeae0ee7
commit b10d106a55
23 changed files with 108 additions and 109 deletions
+8 -7
View File
@@ -10,10 +10,9 @@
package osutil
import (
"fmt"
"os"
"syscall"
"github.com/pkg/errors"
)
const ioprioClassShift = 13
@@ -82,20 +81,22 @@ func SetLowPriority() error {
// so we need this workaround...
if pgid, err := syscall.Getpgid(pidSelf); err != nil {
// This error really shouldn't happen
return errors.Wrap(err, "get process group")
return fmt.Errorf("get process group: %w", err)
} else if pgid != os.Getpid() {
// We are not process group leader. Elevate!
if err := syscall.Setpgid(pidSelf, 0); err != nil {
return errors.Wrap(err, "set process group")
return fmt.Errorf("set process group: %w", err)
}
}
if err := syscall.Setpriority(syscall.PRIO_PGRP, pidSelf, wantNiceLevel); err != nil {
return errors.Wrap(err, "set niceness")
return fmt.Errorf("set niceness: %w", err)
}
// Best effort, somewhere to the end of the scale (0 through 7 being the
// range).
err := ioprioSet(ioprioClassBE, 5)
return errors.Wrap(err, "set I/O priority") // wraps nil as nil
if err := ioprioSet(ioprioClassBE, 5); err != nil {
return fmt.Errorf("set I/O priority: %w", err)
}
return nil
}