2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 05:12:10 +00:00

Merge pull request #3960 from greatroar/errors

errors: Drop WithMessage
This commit is contained in:
Michael Eischer 2022-10-14 21:41:28 +02:00 committed by GitHub
commit 9c290a8093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 17 deletions

View File

@ -457,7 +457,7 @@ func collectTargets(opts BackupOptions, args []string) (targets []string, err er
var expanded []string var expanded []string
expanded, err := filepath.Glob(line) expanded, err := filepath.Glob(line)
if err != nil { if err != nil {
return nil, errors.WithMessage(err, fmt.Sprintf("pattern: %s", line)) return nil, fmt.Errorf("pattern: %s: %w", line, err)
} }
if len(expanded) == 0 { if len(expanded) == 0 {
Warnf("pattern %q does not match any files, skipping\n", line) Warnf("pattern %q does not match any files, skipping\n", line)

View File

@ -2,11 +2,11 @@ package main
import ( import (
"context" "context"
"fmt"
"sync" "sync"
"time" "time"
"github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
) )
@ -45,7 +45,7 @@ func lockRepository(ctx context.Context, repo restic.Repository, exclusive bool)
lock, err := lockFn(ctx, repo) lock, err := lockFn(ctx, repo)
if err != nil { if err != nil {
return nil, ctx, errors.WithMessage(err, "unable to create lock in backend") return nil, ctx, fmt.Errorf("unable to create lock in backend: %w", err)
} }
debug.Log("create lock %p (exclusive %v)", lock, exclusive) debug.Log("create lock %p (exclusive %v)", lock, exclusive)

View File

@ -420,7 +420,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
// make sure it's still a file // make sure it's still a file
if !fs.IsRegularFile(fi) { if !fs.IsRegularFile(fi) {
err = errors.Errorf("file %v changed type, refusing to archive") err = errors.Errorf("file %v changed type, refusing to archive", fi.Name())
_ = file.Close() _ = file.Close()
err = arch.error(abstarget, err) err = arch.error(abstarget, err)
if err != nil { if err != nil {

View File

@ -290,7 +290,7 @@ type Error struct {
Err error Err error
} }
func (e Error) Error() string { func (e *Error) Error() string {
if !e.TreeID.IsNull() { if !e.TreeID.IsNull() {
return "tree " + e.TreeID.String() + ": " + e.Err.Error() return "tree " + e.TreeID.String() + ": " + e.Err.Error()
} }
@ -404,12 +404,12 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
switch node.Type { switch node.Type {
case "file": case "file":
if node.Content == nil { if node.Content == nil {
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q has nil blob list", node.Name)}) errs = append(errs, &Error{TreeID: id, Err: errors.Errorf("file %q has nil blob list", node.Name)})
} }
for b, blobID := range node.Content { for b, blobID := range node.Content {
if blobID.IsNull() { if blobID.IsNull() {
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q blob %d has null ID", node.Name, b)}) errs = append(errs, &Error{TreeID: id, Err: errors.Errorf("file %q blob %d has null ID", node.Name, b)})
continue continue
} }
// Note that we do not use the blob size. The "obvious" check // Note that we do not use the blob size. The "obvious" check
@ -420,7 +420,7 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
_, found := c.repo.LookupBlobSize(blobID, restic.DataBlob) _, found := c.repo.LookupBlobSize(blobID, restic.DataBlob)
if !found { if !found {
debug.Log("tree %v references blob %v which isn't contained in index", id, blobID) debug.Log("tree %v references blob %v which isn't contained in index", id, blobID)
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("file %q blob %v not found in index", node.Name, blobID)}) errs = append(errs, &Error{TreeID: id, Err: errors.Errorf("file %q blob %v not found in index", node.Name, blobID)})
} }
} }
@ -440,12 +440,12 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
case "dir": case "dir":
if node.Subtree == nil { if node.Subtree == nil {
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("dir node %q has no subtree", node.Name)}) errs = append(errs, &Error{TreeID: id, Err: errors.Errorf("dir node %q has no subtree", node.Name)})
continue continue
} }
if node.Subtree.IsNull() { if node.Subtree.IsNull() {
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("dir node %q subtree id is null", node.Name)}) errs = append(errs, &Error{TreeID: id, Err: errors.Errorf("dir node %q subtree id is null", node.Name)})
continue continue
} }
@ -453,11 +453,11 @@ func (c *Checker) checkTree(id restic.ID, tree *restic.Tree) (errs []error) {
// nothing to check // nothing to check
default: default:
errs = append(errs, Error{TreeID: id, Err: errors.Errorf("node %q with invalid type %q", node.Name, node.Type)}) errs = append(errs, &Error{TreeID: id, Err: errors.Errorf("node %q with invalid type %q", node.Name, node.Type)})
} }
if node.Name == "" { if node.Name == "" {
errs = append(errs, Error{TreeID: id, Err: errors.New("node with empty name")}) errs = append(errs, &Error{TreeID: id, Err: errors.New("node with empty name")})
} }
} }

View File

@ -22,10 +22,6 @@ var Wrap = errors.Wrap
// nil, Wrapf returns nil. // nil, Wrapf returns nil.
var Wrapf = errors.Wrapf var Wrapf = errors.Wrapf
// WithMessage annotates err with a new message. If err is nil, WithMessage
// returns nil.
var WithMessage = errors.WithMessage
var WithStack = errors.WithStack var WithStack = errors.WithStack
// Go 1.13-style error handling. // Go 1.13-style error handling.

View File

@ -145,7 +145,7 @@ func SaveTree(ctx context.Context, r BlobSaver, t *Tree) (ID, error) {
return id, err return id, err
} }
var ErrTreeNotOrdered = errors.Errorf("nodes are not ordered or duplicate") var ErrTreeNotOrdered = errors.New("nodes are not ordered or duplicate")
type TreeJSONBuilder struct { type TreeJSONBuilder struct {
buf bytes.Buffer buf bytes.Buffer