Replace fmt.Errorf() by errors.Errorf()

This commit is contained in:
Alexander Neumann
2016-08-21 17:48:36 +02:00
parent 444a268ce0
commit 72aa6be38d
34 changed files with 100 additions and 92 deletions

View File

@@ -240,7 +240,7 @@ func filterExisting(items []string) (result []string, err error) {
func (cmd CmdBackup) readFromStdin(args []string) error {
if len(args) != 0 {
return fmt.Errorf("when reading from stdin, no additional files can be specified")
return errors.Errorf("when reading from stdin, no additional files can be specified")
}
repo, err := cmd.global.OpenRepository()
@@ -274,7 +274,7 @@ func (cmd CmdBackup) Execute(args []string) error {
}
if len(args) == 0 {
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
}
target := make([]string, 0, len(args))
@@ -312,7 +312,7 @@ func (cmd CmdBackup) Execute(args []string) error {
if !cmd.Force && cmd.Parent != "" {
id, err := restic.FindSnapshot(repo, cmd.Parent)
if err != nil {
return fmt.Errorf("invalid id %q: %v", cmd.Parent, err)
return errors.Errorf("invalid id %q: %v", cmd.Parent, err)
}
parentSnapshotID = &id

View File

@@ -26,7 +26,7 @@ func (cmd CmdCache) Usage() string {
func (cmd CmdCache) Execute(args []string) error {
// if len(args) == 0 || len(args) > 2 {
// return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
// return errors.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
// }
repo, err := cmd.global.OpenRepository()

View File

@@ -34,7 +34,7 @@ func (cmd CmdCat) Usage() string {
func (cmd CmdCat) Execute(args []string) error {
if len(args) < 1 || (args[0] != "masterkey" && args[0] != "config" && len(args) != 2) {
return fmt.Errorf("type or ID not specified, Usage: %s", cmd.Usage())
return errors.Errorf("type or ID not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -105,7 +105,7 @@ func (cmd CmdCheck) Execute(args []string) error {
for _, err := range errs {
cmd.global.Warnf("error: %v\n", err)
}
return fmt.Errorf("LoadIndex returned errors")
return errors.Errorf("LoadIndex returned errors")
}
done := make(chan struct{})

View File

@@ -204,7 +204,7 @@ func (cmd CmdDump) DumpIndexes() error {
func (cmd CmdDump) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("type not specified, Usage: %s", cmd.Usage())
return errors.Errorf("type not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -1,10 +1,11 @@
package main
import (
"fmt"
"path/filepath"
"time"
"github.com/pkg/errors"
"restic"
"restic/backend"
"restic/debug"
@@ -57,7 +58,7 @@ func parseTime(str string) (time.Time, error) {
}
}
return time.Time{}, fmt.Errorf("unable to parse time: %q", str)
return time.Time{}, errors.Errorf("unable to parse time: %q", str)
}
func (c CmdFind) findInTree(repo *repository.Repository, id backend.ID, path string) ([]findResult, error) {
@@ -137,7 +138,7 @@ func (CmdFind) Usage() string {
func (c CmdFind) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("wrong number of arguments, Usage: %s", c.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", c.Usage())
}
var err error
@@ -177,7 +178,7 @@ func (c CmdFind) Execute(args []string) error {
if c.Snapshot != "" {
snapshotID, err := restic.FindSnapshot(repo, c.Snapshot)
if err != nil {
return fmt.Errorf("invalid id %q: %v", args[1], err)
return errors.Errorf("invalid id %q: %v", args[1], err)
}
return c.findInSnapshot(repo, snapshotID)

View File

@@ -70,7 +70,7 @@ func (cmd CmdKey) getNewPassword() string {
func (cmd CmdKey) addKey(repo *repository.Repository) error {
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
return errors.Errorf("creating new key failed: %v\n", err)
}
cmd.global.Verbosef("saved new key as %s\n", id)
@@ -95,7 +95,7 @@ func (cmd CmdKey) deleteKey(repo *repository.Repository, name string) error {
func (cmd CmdKey) changePassword(repo *repository.Repository) error {
id, err := repository.AddKey(repo, cmd.getNewPassword(), repo.Key())
if err != nil {
return fmt.Errorf("creating new key failed: %v\n", err)
return errors.Errorf("creating new key failed: %v\n", err)
}
err = repo.Backend().Remove(backend.Key, repo.KeyName())
@@ -114,7 +114,7 @@ func (cmd CmdKey) Usage() string {
func (cmd CmdKey) Execute(args []string) error {
if len(args) < 1 || (args[0] == "rm" && len(args) != 2) {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/pkg/errors"
"restic/backend"
@@ -28,7 +26,7 @@ func (cmd CmdList) Usage() string {
func (cmd CmdList) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("type not specified, Usage: %s", cmd.Usage())
return errors.Errorf("type not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -5,6 +5,8 @@ import (
"os"
"path/filepath"
"github.com/pkg/errors"
"restic"
"restic/backend"
"restic/repository"
@@ -72,7 +74,7 @@ func (cmd CmdLs) Usage() string {
func (cmd CmdLs) Execute(args []string) error {
if len(args) < 1 || len(args) > 2 {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -4,9 +4,10 @@
package main
import (
"fmt"
"os"
"github.com/pkg/errors"
resticfs "restic/fs"
"restic/fuse"
@@ -42,7 +43,7 @@ func (cmd CmdMount) Usage() string {
func (cmd CmdMount) Execute(args []string) error {
if len(args) == 0 {
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -11,6 +11,8 @@ import (
"restic/repository"
"time"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
)
@@ -191,7 +193,7 @@ nextPack:
removePacks.Insert(packID)
if !rewritePacks.Has(packID) {
return fmt.Errorf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
return errors.Errorf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
}
rewritePacks.Delete(packID)

View File

@@ -1,8 +1,6 @@
package main
import (
"fmt"
"github.com/pkg/errors"
"restic"
@@ -37,7 +35,7 @@ func (cmd CmdRestore) Usage() string {
func (cmd CmdRestore) Execute(args []string) error {
if len(args) != 1 {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
if cmd.Target == "" {

View File

@@ -8,6 +8,8 @@ import (
"sort"
"strings"
"github.com/pkg/errors"
"restic"
"restic/backend"
)
@@ -70,7 +72,7 @@ func (cmd CmdSnapshots) Usage() string {
func (cmd CmdSnapshots) Execute(args []string) error {
if len(args) != 0 {
return fmt.Errorf("wrong number of arguments, usage: %s", cmd.Usage())
return errors.Errorf("wrong number of arguments, usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()

View File

@@ -263,7 +263,7 @@ func (o GlobalOptions) OpenRepository() (*repository.Repository, error) {
err = s.SearchKey(o.password, maxKeys)
if err != nil {
return nil, fmt.Errorf("unable to open repo: %v", err)
return nil, errors.Errorf("unable to open repo: %v", err)
}
return s, nil
@@ -301,7 +301,7 @@ func open(s string) (backend.Backend, error) {
}
debug.Log("open", "invalid repository location: %v", s)
return nil, fmt.Errorf("invalid scheme %q", loc.Scheme)
return nil, errors.Errorf("invalid scheme %q", loc.Scheme)
}
// Create the backend specified by URI.
@@ -336,5 +336,5 @@ func create(s string) (backend.Backend, error) {
}
debug.Log("open", "invalid repository scheme: %v", s)
return nil, fmt.Errorf("invalid scheme %q", loc.Scheme)
return nil, errors.Errorf("invalid scheme %q", loc.Scheme)
}

View File

@@ -4,13 +4,14 @@
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"
"github.com/pkg/errors"
"restic"
"restic/backend"
"restic/repository"
@@ -50,7 +51,7 @@ func waitForMount(dir string) error {
time.Sleep(mountSleep)
}
return fmt.Errorf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
return errors.Errorf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
}
func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan struct{}) {

View File

@@ -15,6 +15,8 @@ import (
"testing"
"time"
"github.com/pkg/errors"
"restic/backend"
"restic/debug"
"restic/filter"
@@ -579,7 +581,7 @@ func testFileSize(filename string, size int64) error {
}
if fi.Size() != size {
return fmt.Errorf("wrong file size for %v: expected %v, got %v", filename, size, fi.Size())
return errors.Errorf("wrong file size for %v: expected %v, got %v", filename, size, fi.Size())
}
return nil