Skip to content

Commit

Permalink
chore(storage): Improve error messaging for MP upload missing ETag (#…
Browse files Browse the repository at this point in the history
…14170)

* chore(storage): Improve error messaging for MP upload missing ETag

* Bump size limit
  • Loading branch information
cshfang authored Jan 29, 2025
1 parent e888e7c commit ba025e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
"name": "[Storage] uploadData (S3)",
"path": "./dist/esm/storage/index.mjs",
"import": "{ uploadData }",
"limit": "22.95 kB"
"limit": "23.00 kB"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('completeMultipartUploadSerializer', () => {
],
},
});
console.log(output);
expect(output).toEqual({
$metadata: expect.objectContaining(expectedMetadata),
});
Expand Down Expand Up @@ -140,4 +139,18 @@ describe('completeMultipartUploadSerializer', () => {
}),
).rejects.toThrow(integrityError);
});

it('should fail with specific error messaging when ETag is missing from response', () => {
mockS3TransferHandler.mockResolvedValue(
mockBinaryResponse(completeMultipartUploadSuccessResponse),
);
expect(
completeMultipartUpload(defaultConfig, {
Bucket: 'bucket',
Key: 'key',
UploadId: 'uploadId',
MultipartUpload: { Parts: [{ PartNumber: 1 }] },
}),
).rejects.toThrow('ETag missing');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import type {
} from './types';

const INVALID_PARAMETER_ERROR_MSG =
'Invalid parameter for ComplteMultipartUpload API';
'Invalid parameter for CompleteMultipartUpload API';

const MISSING_ETAG_ERROR_MSG = 'ETag missing from multipart upload';
const MISSING_ETAG_ERROR_SUGGESTION =
'Please ensure S3 bucket CORS configuration includes ETag as part of its `ExposeHeaders` element';

export type CompleteMultipartUploadInput = Pick<
CompleteMultipartUploadCommandInput,
Expand Down Expand Up @@ -95,7 +99,7 @@ const serializeCompletedMultipartUpload = (
input: CompletedMultipartUpload,
): string => {
if (!input.Parts?.length) {
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${input}`);
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${JSON.stringify(input)}`);
}

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

const serializeCompletedPartList = (input: CompletedPart): string => {
if (!input.ETag || input.PartNumber == null) {
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${input}`);
if (input.PartNumber == null) {
throw new Error(`${INVALID_PARAMETER_ERROR_MSG}: ${JSON.stringify(input)}`);
}
if (!input.ETag) {
throw new Error(
`${MISSING_ETAG_ERROR_MSG}: ${JSON.stringify(input)}. ${MISSING_ETAG_ERROR_SUGGESTION}`,
);
}

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

0 comments on commit ba025e5

Please sign in to comment.