Skip to content

Commit ba025e5

Browse files
authored
chore(storage): Improve error messaging for MP upload missing ETag (#14170)
* chore(storage): Improve error messaging for MP upload missing ETag * Bump size limit
1 parent e888e7c commit ba025e5

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

packages/aws-amplify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@
515515
"name": "[Storage] uploadData (S3)",
516516
"path": "./dist/esm/storage/index.mjs",
517517
"import": "{ uploadData }",
518-
"limit": "22.95 kB"
518+
"limit": "23.00 kB"
519519
}
520520
]
521521
}

packages/storage/__tests__/providers/s3/utils/client/s3Data/completeMultipartUpload.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ describe('completeMultipartUploadSerializer', () => {
8383
],
8484
},
8585
});
86-
console.log(output);
8786
expect(output).toEqual({
8887
$metadata: expect.objectContaining(expectedMetadata),
8988
});
@@ -140,4 +139,18 @@ describe('completeMultipartUploadSerializer', () => {
140139
}),
141140
).rejects.toThrow(integrityError);
142141
});
142+
143+
it('should fail with specific error messaging when ETag is missing from response', () => {
144+
mockS3TransferHandler.mockResolvedValue(
145+
mockBinaryResponse(completeMultipartUploadSuccessResponse),
146+
);
147+
expect(
148+
completeMultipartUpload(defaultConfig, {
149+
Bucket: 'bucket',
150+
Key: 'key',
151+
UploadId: 'uploadId',
152+
MultipartUpload: { Parts: [{ PartNumber: 1 }] },
153+
}),
154+
).rejects.toThrow('ETag missing');
155+
});
143156
});

packages/storage/src/providers/s3/utils/client/s3data/completeMultipartUpload.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ import type {
3636
} from './types';
3737

3838
const INVALID_PARAMETER_ERROR_MSG =
39-
'Invalid parameter for ComplteMultipartUpload API';
39+
'Invalid parameter for CompleteMultipartUpload API';
40+
41+
const MISSING_ETAG_ERROR_MSG = 'ETag missing from multipart upload';
42+
const MISSING_ETAG_ERROR_SUGGESTION =
43+
'Please ensure S3 bucket CORS configuration includes ETag as part of its `ExposeHeaders` element';
4044

4145
export type CompleteMultipartUploadInput = Pick<
4246
CompleteMultipartUploadCommandInput,
@@ -95,7 +99,7 @@ const serializeCompletedMultipartUpload = (
9599
input: CompletedMultipartUpload,
96100
): string => {
97101
if (!input.Parts?.length) {
98-
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${input}`);
102+
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${JSON.stringify(input)}`);
99103
}
100104

101105
return `<CompleteMultipartUpload xmlns="http://s3.amazonaws.com/doc/2006-03-01/">${input.Parts.map(
@@ -104,8 +108,13 @@ const serializeCompletedMultipartUpload = (
104108
};
105109

106110
const serializeCompletedPartList = (input: CompletedPart): string => {
107-
if (!input.ETag || input.PartNumber == null) {
108-
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${input}`);
111+
if (input.PartNumber == null) {
112+
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${JSON.stringify(input)}`);
113+
}
114+
if (!input.ETag) {
115+
throw new Error(
116+
`${MISSING_ETAG_ERROR_MSG}: ${JSON.stringify(input)}. ${MISSING_ETAG_ERROR_SUGGESTION}`,
117+
);
109118
}
110119

111120
const eTag = `<ETag>${input.ETag}</ETag>`;

0 commit comments

Comments
 (0)