From 53997ecc791d60b8b69acfa67d1d83f3340067b4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 11 Feb 2024 14:21:08 -0800 Subject: [PATCH] avoid excessive logging for objects that do not exist (#19030) in replicated setups, that have proxying enabled for replicated buckets. --- cmd/api-errors.go | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/cmd/api-errors.go b/cmd/api-errors.go index d95d23225..e387ea6e5 100644 --- a/cmd/api-errors.go +++ b/cmd/api-errors.go @@ -2351,31 +2351,10 @@ func toAPIErrorCode(ctx context.Context, err error) (apiErr APIErrorCode) { case dns.ErrBucketConflict: apiErr = ErrBucketAlreadyExists default: - if _, ok := err.(tags.Error); ok { - // tag errors are not exported, so we check their custom interface to avoid logging. - // The correct type is inserted by toAPIError. - apiErr = ErrInternalError - break - } - var ie, iw int - // This work-around is to handle the issue golang/go#30648 - //nolint:gocritic - if _, ferr := fmt.Fscanf(strings.NewReader(err.Error()), - "request declared a Content-Length of %d but only wrote %d bytes", - &ie, &iw); ferr != nil { - apiErr = ErrInternalError - // Make sure to log the errors which we cannot translate - // to a meaningful S3 API errors. This is added to aid in - // debugging unexpected/unhandled errors. - logger.LogIf(ctx, err) - } else if ie > iw { + if strings.Contains(err.Error(), "requested declared a Content-Length") { apiErr = ErrIncompleteBody } else { apiErr = ErrInternalError - // Make sure to log the errors which we cannot translate - // to a meaningful S3 API errors. This is added to aid in - // debugging unexpected/unhandled errors. - logger.LogIf(ctx, err) } } @@ -2519,6 +2498,13 @@ func toAPIError(ctx context.Context, err error) APIError { } } + if apiErr.Code == "InternalError" { + // Make sure to log the errors which we cannot translate + // to a meaningful S3 API errors. This is added to aid in + // debugging unexpected/unhandled errors. + logger.LogIf(ctx, err) + } + return apiErr }