Skip to content

Commit 107600b

Browse files
ShadowCat567Vieltojarvi
andauthored
Add additional info to The specified bucket does not exist (#2338)
* adding S3 client error handling * more error handling for S3 bucket * specified errorName * revert error catching changes * attempting to catch error in new place * adjust return * change form generator error message to amplifyError * updated model generator error message * fix unintended change * added changeset * remove form generator handling, not necessary * tsconfig fix * removed all changes to form generator * no longer user error * adjust error message * changed to AmplifyFault * updates based on feedback * adjusted error message * another update to error message --------- Co-authored-by: Vieltojarvi <[email protected]>
1 parent 0ef53e2 commit 107600b

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

.changeset/swift-mirrors-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/model-generator': patch
3+
---
4+
5+
Updated error handling with S3 Client

packages/model-generator/src/s3_string_object_fetcher.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { GetObjectCommand, S3Client } from '@aws-sdk/client-s3';
1+
import { AmplifyFault } from '@aws-amplify/platform-core';
2+
import { GetObjectCommand, NoSuchBucket, S3Client } from '@aws-sdk/client-s3';
23

34
/**
45
* Handles fetching an object from an s3 bucket and parsing the object contents to a string
@@ -14,15 +15,30 @@ export class S3StringObjectFetcher {
1415
*/
1516
fetch = async (uri: string) => {
1617
const { bucket, key } = this.parseS3Uri(uri);
17-
const getSchemaCommandResult = await this.s3Client.send(
18-
new GetObjectCommand({ Bucket: bucket, Key: key })
19-
);
20-
const schema = await getSchemaCommandResult.Body?.transformToString();
21-
if (!schema) {
22-
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
23-
throw new Error('Error on parsing output schema');
18+
try {
19+
const getSchemaCommandResult = await this.s3Client.send(
20+
new GetObjectCommand({ Bucket: bucket, Key: key })
21+
);
22+
const schema = await getSchemaCommandResult.Body?.transformToString();
23+
if (!schema) {
24+
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
25+
throw new Error('Error on parsing output schema');
26+
}
27+
return schema;
28+
} catch (caught) {
29+
if (caught instanceof NoSuchBucket) {
30+
throw new AmplifyFault(
31+
'NoSuchBucketFault',
32+
{
33+
message: `${bucket} does not exist. \n
34+
Try redeploying your changes again, if the error persists, create a bug report here: https://github.com/aws-amplify/amplify-backend/issues/new/choose`,
35+
},
36+
caught
37+
);
38+
} else {
39+
throw caught;
40+
}
2441
}
25-
return schema;
2642
};
2743

2844
private parseS3Uri = (uri: string): { bucket: string; key: string } => {

0 commit comments

Comments
 (0)