fix: handle errors appropriately as they are wrapped (#10917)

master
Harshavardhana 4 years ago committed by GitHub
parent 08b24620c0
commit 73e308079a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      cmd/metacache-set.go

@ -21,6 +21,7 @@ import (
"context"
"encoding/gob"
"encoding/json"
"errors"
"fmt"
"io"
"strconv"
@ -371,6 +372,7 @@ func (r *metacacheReader) filter(o listPathOptions) (entries metaCacheEntriesSor
func (er *erasureObjects) streamMetadataParts(ctx context.Context, o listPathOptions) (entries metaCacheEntriesSorted, err error) {
retries := 0
rpc := globalNotificationSys.restClientFromHash(o.Bucket)
for {
select {
case <-ctx.Done():
@ -423,6 +425,7 @@ func (er *erasureObjects) streamMetadataParts(ctx context.Context, o listPathOpt
return entries, fmt.Errorf("reading first part metadata: %w", err)
}
}
if fi.Deleted {
return entries, errFileNotFound
}
@ -559,14 +562,24 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
if debugPrint {
console.Printf("listPath with options: %#v\n", o)
}
// See if we have the listing stored.
if !o.Create && !o.singleObject {
entries, err := er.streamMetadataParts(ctx, o)
switch err {
case nil, io.EOF, context.Canceled, context.DeadlineExceeded:
return entries, err
if IsErr(err, []error{
nil,
context.Canceled,
context.DeadlineExceeded,
}...) {
// Expected good errors we don't need to return error.
return entries, nil
}
if !errors.Is(err, io.EOF) { // io.EOF is expected and should be returned but no need to log it.
// Log an return errors on unexpected errors.
logger.LogIf(ctx, err)
}
return entries, err
}
@ -587,7 +600,7 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
if debugPrint {
console.Println("listPath returning:", entries.len(), "err:", err)
}
if err != nil && err != io.EOF {
if err != nil && !errors.Is(err, io.EOF) {
go func(err string) {
metaMu.Lock()
if meta.status != scanStateError {

Loading…
Cancel
Save