multi: fix fmt.Errorf error wrapping

Refactor fmt.Errorf usage to correctly wrap errors instead of using
non-wrapping format verbs.
This commit is contained in:
ffranr committed 2024-02-27 11:13:40 +00:00
1 parent 581c16d72f
commit cd566eb097
103 files changed
+426 -390

No files matched your search

+5 -4
View File
@@ -93,17 +93,18 @@ func (b *MultiFile) UpdateAndSwap(newBackup PackedMulti) error {
var err error
b.tempFile, err = os.Create(b.tempFileName)
if err != nil {
return fmt.Errorf("unable to create temp file: %v", err)
return fmt.Errorf("unable to create temp file: %w", err)
}
// With the file created, we'll write the new packed multi backup and
// remove the temporary file all together once this method exits.
_, err = b.tempFile.Write([]byte(newBackup))
if err != nil {
return fmt.Errorf("unable to write backup to temp file: %v", err)
return fmt.Errorf("unable to write backup to temp file: %w",
err)
}
if err := b.tempFile.Sync(); err != nil {
return fmt.Errorf("unable to sync temp file: %v", err)
return fmt.Errorf("unable to sync temp file: %w", err)
}
defer os.Remove(b.tempFileName)
@@ -114,7 +115,7 @@ func (b *MultiFile) UpdateAndSwap(newBackup PackedMulti) error {
// sure to close the current file as some OSes don't support
// renaming a file that's already open (Windows).
if err := b.tempFile.Close(); err != nil {
return fmt.Errorf("unable to close file: %v", err)
return fmt.Errorf("unable to close file: %w", err)
}
// Finally, we'll attempt to atomically rename the temporary file to