From 74179aafdfcaa36cbe2f337e116e1f95eeb17bdc Mon Sep 17 00:00:00 2001 From: Viv Lim Date: Mon, 24 Jul 2023 20:34:37 -0700 Subject: [PATCH] Log the assembled S3 url if constructing a S3 client fails. I was configuring an instance and didn't notice that I had pasted a space into the `endpoint` field. It was not obvious from the logs why the URL was invalid. --- packages/backend/src/services/drive/s3.ts | 30 +++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/backend/src/services/drive/s3.ts b/packages/backend/src/services/drive/s3.ts index ca356e9124..80a9dfece4 100644 --- a/packages/backend/src/services/drive/s3.ts +++ b/packages/backend/src/services/drive/s3.ts @@ -11,17 +11,21 @@ export function getS3(meta: Meta) { }` : `${meta.objectStorageUseSSL ? "https://" : "http://"}example.net`; - return new S3({ - endpoint: meta.objectStorageEndpoint || undefined, - accessKeyId: meta.objectStorageAccessKey!, - secretAccessKey: meta.objectStorageSecretKey!, - region: meta.objectStorageRegion || undefined, - sslEnabled: meta.objectStorageUseSSL, - s3ForcePathStyle: !meta.objectStorageEndpoint // AWS with endPoint omitted - ? false - : meta.objectStorageS3ForcePathStyle, - httpOptions: { - agent: getAgentByUrl(new URL(u), !meta.objectStorageUseProxy), - }, - }); + try { + return new S3({ + endpoint: meta.objectStorageEndpoint || undefined, + accessKeyId: meta.objectStorageAccessKey!, + secretAccessKey: meta.objectStorageSecretKey!, + region: meta.objectStorageRegion || undefined, + sslEnabled: meta.objectStorageUseSSL, + s3ForcePathStyle: !meta.objectStorageEndpoint // AWS with endPoint omitted + ? false + : meta.objectStorageS3ForcePathStyle, + httpOptions: { + agent: getAgentByUrl(new URL(u), !meta.objectStorageUseProxy), + }, + }); + } catch (e) { + throw new Error(`Failed to construct S3 client, assembled S3 URL: ${u}\n${e}`); + } }