repository: Push all usage of errors.Fatal out of the package

As the `Fatal` error type only includes a string, it becomes impossible
to inspect the contained error. This is for a example a problem for the
fuse implementation, which must be able to detect context.Canceled
errors.

Co-authored-by: greatroar <61184462+greatroar@users.noreply.github.com>
This commit is contained in:
Michael Eischerandgreatroar committed 2023-05-18 17:27:41 +02:00
1 parent a013014c24
commit 5773b86d02
7 files changed
+18 -14

No files matched your search

+8 -8
View File
@@ -110,16 +110,16 @@ func (c *CompressionMode) Type() string {
// New returns a new repository with backend be.
func New(be restic.Backend, opts Options) (*Repository, error) {
if opts.Compression == CompressionInvalid {
return nil, errors.Fatalf("invalid compression mode")
return nil, errors.New("invalid compression mode")
}
if opts.PackSize == 0 {
opts.PackSize = DefaultPackSize
}
if opts.PackSize > MaxPackSize {
return nil, errors.Fatalf("pack size larger than limit of %v MiB", MaxPackSize/1024/1024)
return nil, fmt.Errorf("pack size larger than limit of %v MiB", MaxPackSize/1024/1024)
} else if opts.PackSize < MinPackSize {
return nil, errors.Fatalf("pack size smaller than minimum of %v MiB", MinPackSize/1024/1024)
return nil, fmt.Errorf("pack size smaller than minimum of %v MiB", MinPackSize/1024/1024)
}
repo := &Repository{
@@ -593,7 +593,7 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
})
if err != nil {
return errors.Fatal(err.Error())
return err
}
err = r.idx.MergeFinalIndexes()
@@ -613,7 +613,7 @@ func (r *Repository) LoadIndex(ctx context.Context) error {
}
})
if invalidIndex {
return errors.Fatal("index uses feature not supported by repository version 1")
return errors.New("index uses feature not supported by repository version 1")
}
}
@@ -678,7 +678,7 @@ func (r *Repository) CreateIndexFromPacks(ctx context.Context, packsize map[rest
err = wg.Wait()
if err != nil {
return invalid, errors.Fatal(err.Error())
return invalid, err
}
return invalid, nil
@@ -723,9 +723,9 @@ func (r *Repository) SearchKey(ctx context.Context, password string, maxKeys int
r.keyID = key.ID()
cfg, err := restic.LoadConfig(ctx, r)
if err == crypto.ErrUnauthenticated {
return errors.Fatalf("config or key %v is damaged: %v", key.ID(), err)
return fmt.Errorf("config or key %v is damaged: %w", key.ID(), err)
} else if err != nil {
return errors.Fatalf("config cannot be loaded: %v", err)
return fmt.Errorf("config cannot be loaded: %w", err)
}
r.setConfig(cfg)