*: fmt.Errorf: use %w when appropriate

This should result in no change when the error is printed, but make the
errors returned unwrappable, meaning errors.As and errors.Is will work.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-06-08 20:05:54 -07:00
parent d8ba4128b2
commit 7be93a66b9
20 changed files with 50 additions and 49 deletions
+2 -2
View File
@@ -414,7 +414,7 @@ func writeFile(dir, file, data string) error {
return fmt.Errorf("no such directory for %s", file)
}
if err := ioutil.WriteFile(filepath.Join(dir, file), []byte(data+"\n"), 0o600); err != nil {
return fmt.Errorf("failed to write %v: %v", data, err)
return fmt.Errorf("failed to write %v: %w", data, err)
}
return nil
}
@@ -521,7 +521,7 @@ func WriteIntelRdtTasks(dir string, pid int) error {
// Don't attach any pid if -1 is specified as a pid
if pid != -1 {
if err := ioutil.WriteFile(filepath.Join(dir, IntelRdtTasks), []byte(strconv.Itoa(pid)), 0o600); err != nil {
return fmt.Errorf("failed to write %v: %v", pid, err)
return fmt.Errorf("failed to write %v: %w", pid, err)
}
}
return nil