mirror of
https://github.com/restic/restic.git
synced 2026-04-29 15:59:25 +00:00
Create package restic/errors
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"restic/errors"
|
||||
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
@@ -232,7 +232,7 @@ func filterExisting(items []string) (result []string, err error) {
|
||||
}
|
||||
|
||||
if len(result) == 0 {
|
||||
return nil, restic.Fatal("all target directories/files do not exist")
|
||||
return nil, errors.Fatal("all target directories/files do not exist")
|
||||
}
|
||||
|
||||
return
|
||||
@@ -240,7 +240,7 @@ func filterExisting(items []string) (result []string, err error) {
|
||||
|
||||
func (cmd CmdBackup) readFromStdin(args []string) error {
|
||||
if len(args) != 0 {
|
||||
return restic.Fatalf("when reading from stdin, no additional files can be specified")
|
||||
return errors.Fatalf("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 restic.Fatalf("wrong number of parameters, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("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 restic.Fatalf("invalid id %q: %v", cmd.Parent, err)
|
||||
return errors.Fatalf("invalid id %q: %v", cmd.Parent, err)
|
||||
}
|
||||
|
||||
parentSnapshotID = &id
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"restic"
|
||||
"restic/backend"
|
||||
"restic/debug"
|
||||
"restic/errors"
|
||||
"restic/repository"
|
||||
)
|
||||
|
||||
@@ -31,7 +32,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 restic.Fatalf("type or ID not specified, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("type or ID not specified, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
@@ -52,7 +53,7 @@ func (cmd CmdCat) Execute(args []string) error {
|
||||
id, err = restic.ParseID(args[1])
|
||||
if err != nil {
|
||||
if tpe != "snapshot" {
|
||||
return restic.Fatalf("unable to parse ID: %v\n", err)
|
||||
return errors.Fatalf("unable to parse ID: %v\n", err)
|
||||
}
|
||||
|
||||
// find snapshot id with prefix
|
||||
@@ -181,7 +182,7 @@ func (cmd CmdCat) Execute(args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return restic.Fatal("blob not found")
|
||||
return errors.Fatal("blob not found")
|
||||
|
||||
case "tree":
|
||||
debug.Log("cat", "cat tree %v", id.Str())
|
||||
@@ -202,6 +203,6 @@ func (cmd CmdCat) Execute(args []string) error {
|
||||
return nil
|
||||
|
||||
default:
|
||||
return restic.Fatal("invalid type")
|
||||
return errors.Fatal("invalid type")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"restic"
|
||||
"restic/checker"
|
||||
"restic/errors"
|
||||
)
|
||||
|
||||
type CmdCheck struct {
|
||||
@@ -65,7 +66,7 @@ func (cmd CmdCheck) newReadProgress(todo restic.Stat) *restic.Progress {
|
||||
|
||||
func (cmd CmdCheck) Execute(args []string) error {
|
||||
if len(args) != 0 {
|
||||
return restic.Fatal("check has no arguments")
|
||||
return errors.Fatal("check has no arguments")
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
@@ -103,7 +104,7 @@ func (cmd CmdCheck) Execute(args []string) error {
|
||||
for _, err := range errs {
|
||||
cmd.global.Warnf("error: %v\n", err)
|
||||
}
|
||||
return restic.Fatal("LoadIndex returned errors")
|
||||
return errors.Fatal("LoadIndex returned errors")
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
@@ -158,7 +159,7 @@ func (cmd CmdCheck) Execute(args []string) error {
|
||||
}
|
||||
|
||||
if errorsFound {
|
||||
return restic.Fatal("repository contains errors")
|
||||
return errors.Fatal("repository contains errors")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
|
||||
"restic"
|
||||
"restic/errors"
|
||||
"restic/pack"
|
||||
"restic/repository"
|
||||
|
||||
@@ -170,7 +171,7 @@ func (cmd CmdDump) DumpIndexes() error {
|
||||
|
||||
func (cmd CmdDump) Execute(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return restic.Fatalf("type not specified, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("type not specified, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
@@ -214,6 +215,6 @@ func (cmd CmdDump) Execute(args []string) error {
|
||||
|
||||
return nil
|
||||
default:
|
||||
return restic.Fatalf("no such type %q", tpe)
|
||||
return errors.Fatalf("no such type %q", tpe)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"restic"
|
||||
"restic/debug"
|
||||
"restic/errors"
|
||||
"restic/repository"
|
||||
)
|
||||
|
||||
@@ -55,7 +56,7 @@ func parseTime(str string) (time.Time, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return time.Time{}, restic.Fatalf("unable to parse time: %q", str)
|
||||
return time.Time{}, errors.Fatalf("unable to parse time: %q", str)
|
||||
}
|
||||
|
||||
func (c CmdFind) findInTree(repo *repository.Repository, id restic.ID, path string) ([]findResult, error) {
|
||||
@@ -135,7 +136,7 @@ func (CmdFind) Usage() string {
|
||||
|
||||
func (c CmdFind) Execute(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return restic.Fatalf("wrong number of arguments, Usage: %s", c.Usage())
|
||||
return errors.Fatalf("wrong number of arguments, Usage: %s", c.Usage())
|
||||
}
|
||||
|
||||
var err error
|
||||
@@ -175,7 +176,7 @@ func (c CmdFind) Execute(args []string) error {
|
||||
if c.Snapshot != "" {
|
||||
snapshotID, err := restic.FindSnapshot(repo, c.Snapshot)
|
||||
if err != nil {
|
||||
return restic.Fatalf("invalid id %q: %v", args[1], err)
|
||||
return errors.Fatalf("invalid id %q: %v", args[1], err)
|
||||
}
|
||||
|
||||
return c.findInSnapshot(repo, snapshotID)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"restic"
|
||||
"restic/errors"
|
||||
"restic/repository"
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ type CmdInit struct {
|
||||
|
||||
func (cmd CmdInit) Execute(args []string) error {
|
||||
if cmd.global.Repo == "" {
|
||||
return restic.Fatal("Please specify repository location (-r)")
|
||||
return errors.Fatal("Please specify repository location (-r)")
|
||||
}
|
||||
|
||||
be, err := create(cmd.global.Repo)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"restic"
|
||||
|
||||
"restic/errors"
|
||||
"restic/repository"
|
||||
)
|
||||
|
||||
@@ -68,7 +69,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 restic.Fatalf("creating new key failed: %v\n", err)
|
||||
return errors.Fatalf("creating new key failed: %v\n", err)
|
||||
}
|
||||
|
||||
cmd.global.Verbosef("saved new key as %s\n", id)
|
||||
@@ -78,7 +79,7 @@ func (cmd CmdKey) addKey(repo *repository.Repository) error {
|
||||
|
||||
func (cmd CmdKey) deleteKey(repo *repository.Repository, name string) error {
|
||||
if name == repo.KeyName() {
|
||||
return restic.Fatal("refusing to remove key currently used to access repository")
|
||||
return errors.Fatal("refusing to remove key currently used to access repository")
|
||||
}
|
||||
|
||||
err := repo.Backend().Remove(restic.KeyFile, name)
|
||||
@@ -93,7 +94,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 restic.Fatalf("creating new key failed: %v\n", err)
|
||||
return errors.Fatalf("creating new key failed: %v\n", err)
|
||||
}
|
||||
|
||||
err = repo.Backend().Remove(restic.KeyFile, repo.KeyName())
|
||||
@@ -112,7 +113,7 @@ func (cmd CmdKey) Usage() string {
|
||||
|
||||
func (cmd CmdKey) Execute(args []string) error {
|
||||
if len(args) < 1 || (args[0] == "rm" && len(args) != 2) {
|
||||
return restic.Fatalf("wrong number of arguments, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("wrong number of arguments, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package main
|
||||
|
||||
import "restic"
|
||||
import (
|
||||
"restic"
|
||||
"restic/errors"
|
||||
)
|
||||
|
||||
type CmdList struct {
|
||||
global *GlobalOptions
|
||||
@@ -22,7 +25,7 @@ func (cmd CmdList) Usage() string {
|
||||
|
||||
func (cmd CmdList) Execute(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return restic.Fatalf("type not specified, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("type not specified, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
@@ -51,7 +54,7 @@ func (cmd CmdList) Execute(args []string) error {
|
||||
case "locks":
|
||||
t = restic.LockFile
|
||||
default:
|
||||
return restic.Fatal("invalid type")
|
||||
return errors.Fatal("invalid type")
|
||||
}
|
||||
|
||||
for id := range repo.List(t, nil) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"restic"
|
||||
"restic/errors"
|
||||
"restic/repository"
|
||||
)
|
||||
|
||||
@@ -71,7 +72,7 @@ func (cmd CmdLs) Usage() string {
|
||||
|
||||
func (cmd CmdLs) Execute(args []string) error {
|
||||
if len(args) < 1 || len(args) > 2 {
|
||||
return restic.Fatalf("wrong number of arguments, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("wrong number of arguments, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
|
||||
@@ -5,9 +5,8 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"restic"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"restic/errors"
|
||||
|
||||
resticfs "restic/fs"
|
||||
"restic/fuse"
|
||||
@@ -44,7 +43,7 @@ func (cmd CmdMount) Usage() string {
|
||||
|
||||
func (cmd CmdMount) Execute(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return restic.Fatalf("wrong number of parameters, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("wrong number of parameters, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"restic"
|
||||
"restic/debug"
|
||||
"restic/errors"
|
||||
"restic/index"
|
||||
"restic/repository"
|
||||
"time"
|
||||
@@ -189,7 +190,7 @@ nextPack:
|
||||
removePacks.Insert(packID)
|
||||
|
||||
if !rewritePacks.Has(packID) {
|
||||
return restic.Fatalf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
|
||||
return errors.Fatalf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
|
||||
}
|
||||
|
||||
rewritePacks.Delete(packID)
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"restic"
|
||||
"restic/debug"
|
||||
"restic/errors"
|
||||
"restic/filter"
|
||||
)
|
||||
|
||||
@@ -32,15 +33,15 @@ func (cmd CmdRestore) Usage() string {
|
||||
|
||||
func (cmd CmdRestore) Execute(args []string) error {
|
||||
if len(args) != 1 {
|
||||
return restic.Fatalf("wrong number of arguments, Usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("wrong number of arguments, Usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
if cmd.Target == "" {
|
||||
return restic.Fatal("please specify a directory to restore to (--target)")
|
||||
return errors.Fatal("please specify a directory to restore to (--target)")
|
||||
}
|
||||
|
||||
if len(cmd.Exclude) > 0 && len(cmd.Include) > 0 {
|
||||
return restic.Fatal("exclude and include patterns are mutually exclusive")
|
||||
return errors.Fatal("exclude and include patterns are mutually exclusive")
|
||||
}
|
||||
|
||||
snapshotIDString := args[0]
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"restic/errors"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -69,7 +70,7 @@ func (cmd CmdSnapshots) Usage() string {
|
||||
|
||||
func (cmd CmdSnapshots) Execute(args []string) error {
|
||||
if len(args) != 0 {
|
||||
return restic.Fatalf("wrong number of arguments, usage: %s", cmd.Usage())
|
||||
return errors.Fatalf("wrong number of arguments, usage: %s", cmd.Usage())
|
||||
}
|
||||
|
||||
repo, err := cmd.global.OpenRepository()
|
||||
|
||||
@@ -17,8 +17,9 @@ import (
|
||||
"restic/location"
|
||||
"restic/repository"
|
||||
|
||||
"restic/errors"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
@@ -246,7 +247,7 @@ const maxKeys = 20
|
||||
// OpenRepository reads the password and opens the repository.
|
||||
func (o GlobalOptions) OpenRepository() (*repository.Repository, error) {
|
||||
if o.Repo == "" {
|
||||
return nil, restic.Fatal("Please specify repository location (-r)")
|
||||
return nil, errors.Fatal("Please specify repository location (-r)")
|
||||
}
|
||||
|
||||
be, err := open(o.Repo)
|
||||
@@ -262,7 +263,7 @@ func (o GlobalOptions) OpenRepository() (*repository.Repository, error) {
|
||||
|
||||
err = s.SearchKey(o.password, maxKeys)
|
||||
if err != nil {
|
||||
return nil, restic.Fatalf("unable to open repo: %v", err)
|
||||
return nil, errors.Fatalf("unable to open repo: %v", err)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
@@ -300,7 +301,7 @@ func open(s string) (restic.Backend, error) {
|
||||
}
|
||||
|
||||
debug.Log("open", "invalid repository location: %v", s)
|
||||
return nil, restic.Fatalf("invalid scheme %q", loc.Scheme)
|
||||
return nil, errors.Fatalf("invalid scheme %q", loc.Scheme)
|
||||
}
|
||||
|
||||
// Create the backend specified by URI.
|
||||
@@ -335,5 +336,5 @@ func create(s string) (restic.Backend, error) {
|
||||
}
|
||||
|
||||
debug.Log("open", "invalid repository scheme: %v", s)
|
||||
return nil, restic.Fatalf("invalid scheme %q", loc.Scheme)
|
||||
return nil, errors.Fatalf("invalid scheme %q", loc.Scheme)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"restic/errors"
|
||||
|
||||
"restic"
|
||||
"restic/repository"
|
||||
@@ -50,7 +50,7 @@ func waitForMount(dir string) error {
|
||||
time.Sleep(mountSleep)
|
||||
}
|
||||
|
||||
return restic.Fatalf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
|
||||
return errors.Fatalf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
|
||||
}
|
||||
|
||||
func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan struct{}) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"restic/errors"
|
||||
|
||||
"restic/debug"
|
||||
"restic/filter"
|
||||
@@ -582,7 +582,7 @@ func testFileSize(filename string, size int64) error {
|
||||
}
|
||||
|
||||
if fi.Size() != size {
|
||||
return restic.Fatalf("wrong file size for %v: expected %v, got %v", filename, size, fi.Size())
|
||||
return errors.Fatalf("wrong file size for %v: expected %v, got %v", filename, size, fi.Size())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -7,8 +7,9 @@ import (
|
||||
"restic/debug"
|
||||
"runtime"
|
||||
|
||||
"restic/errors"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -42,7 +43,7 @@ func main() {
|
||||
switch {
|
||||
case restic.IsAlreadyLocked(errors.Cause(err)):
|
||||
fmt.Fprintf(os.Stderr, "%v\nthe `unlock` command can be used to remove stale locks\n", err)
|
||||
case restic.IsFatal(errors.Cause(err)):
|
||||
case errors.IsFatal(errors.Cause(err)):
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
case err != nil:
|
||||
fmt.Fprintf(os.Stderr, "%+v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user