mirror of
https://github.com/restic/restic.git
synced 2025-10-09 07:33:53 +00:00
errors: Drop Cause in favor of Go 1.13 error handling
The only use cases in the code were in errors.IsFatal, backend/b2, which needs a workaround, and backend.ParseLayout. The last of these requires all backends to implement error unwrapping in IsNotExist. All backends except gs already did that.
This commit is contained in:
@@ -184,7 +184,14 @@ func (be *b2Backend) HasAtomicReplace() bool {
|
||||
|
||||
// IsNotExist returns true if the error is caused by a non-existing file.
|
||||
func (be *b2Backend) IsNotExist(err error) bool {
|
||||
return b2.IsNotExist(errors.Cause(err))
|
||||
// blazer/b2 does not export its error types and values,
|
||||
// so we can't use errors.{As,Is}.
|
||||
for ; err != nil; err = errors.Unwrap(err) {
|
||||
if b2.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Load runs fn with a reader that yields the contents of the file at h at the
|
||||
@@ -386,7 +393,7 @@ func (be *b2Backend) Delete(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
err := be.Remove(ctx, restic.Handle{Type: restic.ConfigFile})
|
||||
if err != nil && b2.IsNotExist(errors.Cause(err)) {
|
||||
if err != nil && be.IsNotExist(err) {
|
||||
err = nil
|
||||
}
|
||||
|
||||
|
@@ -174,13 +174,8 @@ func (be *Backend) IsNotExist(err error) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
if er, ok := err.(*googleapi.Error); ok {
|
||||
if er.Code == 404 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
var gerr *googleapi.Error
|
||||
return errors.As(err, &gerr) && gerr.Code == 404
|
||||
}
|
||||
|
||||
// Join combines path components with slashes.
|
||||
|
@@ -71,7 +71,7 @@ var backendFilename = regexp.MustCompile(fmt.Sprintf("^[a-fA-F0-9]{%d}$", backen
|
||||
|
||||
func hasBackendFile(ctx context.Context, fs Filesystem, dir string) (bool, error) {
|
||||
entries, err := fs.ReadDir(ctx, dir)
|
||||
if err != nil && fs.IsNotExist(errors.Cause(err)) {
|
||||
if err != nil && fs.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user