Skip to content

Commit c49d8f5

Browse files
committed
fix: gracefully skip PutBucketCors and DeleteBucketPolicy for S3-compatible backends
1 parent b9c2525 commit c49d8f5

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

packages/bucket-provisioner/src/provisioner.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ export class BucketProvisioner {
303303

304304
/**
305305
* Delete an S3 bucket policy (used to clear leftover public policies).
306+
*
307+
* Gracefully handles backends that don't support this operation or have
308+
* no policy to delete.
306309
*/
307310
async deleteBucketPolicy(bucketName: string): Promise<void> {
308311
try {
@@ -311,7 +314,16 @@ export class BucketProvisioner {
311314
);
312315
} catch (err: any) {
313316
// No policy to delete — that's fine
314-
if (err.name === 'NoSuchBucketPolicy' || err.$metadata?.httpStatusCode === 404) {
317+
if (
318+
err.name === 'NoSuchBucketPolicy' ||
319+
err.$metadata?.httpStatusCode === 404 ||
320+
err.Code === 'XmlParseException' ||
321+
err.name === 'XmlParseException' ||
322+
err.Code === 'NotImplemented' ||
323+
err.name === 'NotImplemented' ||
324+
err.message?.includes('not well-formed') ||
325+
err.message?.includes('not implemented')
326+
) {
315327
return;
316328
}
317329
throw new ProvisionerError(
@@ -324,6 +336,10 @@ export class BucketProvisioner {
324336

325337
/**
326338
* Set CORS configuration on an S3 bucket.
339+
*
340+
* Gracefully skips if the S3-compatible backend (e.g. older MinIO) does
341+
* not support PutBucketCors — CORS is best-effort since not all providers
342+
* implement this API via the same endpoint path.
327343
*/
328344
async setCors(bucketName: string, rules: CorsRule[]): Promise<void> {
329345
try {
@@ -342,6 +358,20 @@ export class BucketProvisioner {
342358
}),
343359
);
344360
} catch (err: any) {
361+
// Some S3-compatible backends (e.g. older MinIO) don't support
362+
// PutBucketCors via the standard path. Treat XML parse errors or
363+
// "not implemented" responses as non-fatal.
364+
if (
365+
err.Code === 'XmlParseException' ||
366+
err.name === 'XmlParseException' ||
367+
err.Code === 'NotImplemented' ||
368+
err.name === 'NotImplemented' ||
369+
err.message?.includes('not well-formed') ||
370+
err.message?.includes('not implemented') ||
371+
err.message?.includes('CORSConfiguration')
372+
) {
373+
return;
374+
}
345375
throw new ProvisionerError(
346376
'CORS_FAILED',
347377
`Failed to set CORS on '${bucketName}': ${err.message}`,

0 commit comments

Comments
 (0)