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
+5 -6
View File
@@ -8,12 +8,11 @@ package syncthing
import (
"crypto/tls"
"errors"
"fmt"
"io"
"os"
"github.com/pkg/errors"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/db/backend"
"github.com/syncthing/syncthing/lib/events"
@@ -93,17 +92,17 @@ func LoadConfigAtStartup(path string, cert tls.Certificate, evLogger events.Logg
if fs.IsNotExist(err) {
cfg, err = DefaultConfig(path, myID, evLogger, noDefaultFolder, skipPortProbing)
if err != nil {
return nil, errors.Wrap(err, "failed to generate default config")
return nil, fmt.Errorf("failed to generate default config: %w", err)
}
err = cfg.Save()
if err != nil {
return nil, errors.Wrap(err, "failed to save default config")
return nil, fmt.Errorf("failed to save default config: %w", err)
}
l.Infof("Default config saved. Edit %s to taste (with Syncthing stopped) or use the GUI", cfg.ConfigPath())
} else if err == io.EOF {
return nil, errors.New("failed to load config: unexpected end of file. Truncated or empty configuration?")
} else if err != nil {
return nil, errors.Wrap(err, "failed to load config")
return nil, fmt.Errorf("failed to load config: %w", err)
}
if originalVersion != config.CurrentVersion {
@@ -115,7 +114,7 @@ func LoadConfigAtStartup(path string, cert tls.Certificate, evLogger events.Logg
}
err = archiveAndSaveConfig(cfg, originalVersion)
if err != nil {
return nil, errors.Wrap(err, "config archive")
return nil, fmt.Errorf("config archive: %w", err)
}
}