From 5d5d0d4ce95ee6df23ea09f48370902d7bee7438 Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 25 Jul 2025 19:15:18 +0800 Subject: [PATCH] Improve error messages in S3 storage operations - Enhanced error handling in the S3 storage implementation by including the fileID in error messages for upload, upload chunk, merge chunks, and download operations. This change provides clearer context for debugging and improves the overall error reporting mechanism. --- attachment/s3/storage.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/attachment/s3/storage.go b/attachment/s3/storage.go index 83b6f637..49b7a935 100644 --- a/attachment/s3/storage.go +++ b/attachment/s3/storage.go @@ -122,7 +122,7 @@ func (storage *Storage) Upload(ctx context.Context, fileID string, reader io.Rea ContentType: aws.String(contentType), }) if err != nil { - return "", fmt.Errorf("failed to upload file: %w", err) + return "", fmt.Errorf("failed to upload file %s: %w", fileID, err) } return fileID, nil @@ -144,7 +144,7 @@ func (storage *Storage) UploadChunk(ctx context.Context, fileID string, chunkInd ContentType: aws.String(contentType), }) if err != nil { - return fmt.Errorf("failed to upload chunk %d: %w", chunkIndex, err) + return fmt.Errorf("failed to upload chunk %s %d: %w", fileID, chunkIndex, err) } return nil @@ -182,7 +182,7 @@ func (storage *Storage) MergeChunks(ctx context.Context, fileID string, totalChu _, err = io.Copy(&mergedContent, result.Body) result.Body.Close() if err != nil { - return fmt.Errorf("failed to copy chunk %d: %w", i, err) + return fmt.Errorf("failed to copy chunk %s %d: %w", fileID, i, err) } } @@ -199,7 +199,7 @@ func (storage *Storage) MergeChunks(ctx context.Context, fileID string, totalChu ContentType: aws.String(contentType), }) if err != nil { - return fmt.Errorf("failed to upload merged file: %w", err) + return fmt.Errorf("failed to upload merged file %s: %w", fileID, err) } // Clean up chunks @@ -227,7 +227,7 @@ func (storage *Storage) Reader(ctx context.Context, fileID string) (io.ReadClose Key: aws.String(key), }) if err != nil { - return nil, fmt.Errorf("failed to get file: %w", err) + return nil, fmt.Errorf("failed to get file %s: %w", fileID, err) } // If the file is a gzip file, decompress it @@ -256,7 +256,7 @@ func (storage *Storage) Download(ctx context.Context, fileID string) (io.ReadClo Key: aws.String(key), }) if err != nil { - return nil, "", fmt.Errorf("failed to download file: %w", err) + return nil, "", fmt.Errorf("failed to download file %s: %w", fileID, err) } contentType := "application/octet-stream"