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

This commit is contained in:
Harshavardhana 2020-11-20 10:43:07 -08:00 committed by GitHub
parent 08b24620c0
commit 73e308079a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,7 @@ import (
"context" "context"
"encoding/gob" "encoding/gob"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"strconv" "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) { func (er *erasureObjects) streamMetadataParts(ctx context.Context, o listPathOptions) (entries metaCacheEntriesSorted, err error) {
retries := 0 retries := 0
rpc := globalNotificationSys.restClientFromHash(o.Bucket) rpc := globalNotificationSys.restClientFromHash(o.Bucket)
for { for {
select { select {
case <-ctx.Done(): 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) return entries, fmt.Errorf("reading first part metadata: %w", err)
} }
} }
if fi.Deleted { if fi.Deleted {
return entries, errFileNotFound return entries, errFileNotFound
} }
@ -559,14 +562,24 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
if debugPrint { if debugPrint {
console.Printf("listPath with options: %#v\n", o) console.Printf("listPath with options: %#v\n", o)
} }
// See if we have the listing stored. // See if we have the listing stored.
if !o.Create && !o.singleObject { if !o.Create && !o.singleObject {
entries, err := er.streamMetadataParts(ctx, o) entries, err := er.streamMetadataParts(ctx, o)
switch err { if IsErr(err, []error{
case nil, io.EOF, context.Canceled, context.DeadlineExceeded: nil,
return entries, err context.Canceled,
context.DeadlineExceeded,
}...) {
// Expected good errors we don't need to return error.
return entries, nil
} }
logger.LogIf(ctx, err)
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 return entries, err
} }
@ -587,7 +600,7 @@ func (er *erasureObjects) listPath(ctx context.Context, o listPathOptions) (entr
if debugPrint { if debugPrint {
console.Println("listPath returning:", entries.len(), "err:", err) 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) { go func(err string) {
metaMu.Lock() metaMu.Lock()
if meta.status != scanStateError { if meta.status != scanStateError {