From 4ddaa970800ec8487cc3403282a590b909dffb32 Mon Sep 17 00:00:00 2001 From: George Fu Date: Tue, 8 Oct 2024 13:44:20 -0400 Subject: [PATCH] fix(middleware-user-agent): ignore errors from inspecting credentials (#6551) --- .../src/check-features.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/middleware-user-agent/src/check-features.ts b/packages/middleware-user-agent/src/check-features.ts index 4a747f89e70c..0c808d5dcf4d 100644 --- a/packages/middleware-user-agent/src/check-features.ts +++ b/packages/middleware-user-agent/src/check-features.ts @@ -43,12 +43,19 @@ export async function checkFeatures( } if (typeof config.credentials === "function") { - const credentials: AttributedAwsCredentialIdentity = await config.credentials?.(); - if (credentials.accountId) { - setFeature(context, "RESOLVED_ACCOUNT_ID", "T"); - } - for (const [key, value] of Object.entries(credentials.$source ?? {})) { - setFeature(context, key as keyof AwsSdkCredentialsFeatures, value); + try { + const credentials: AttributedAwsCredentialIdentity = await config.credentials?.(); + if (credentials.accountId) { + setFeature(context, "RESOLVED_ACCOUNT_ID", "T"); + } + for (const [key, value] of Object.entries(credentials.$source ?? {})) { + setFeature(context, key as keyof AwsSdkCredentialsFeatures, value); + } + } catch (e: unknown) { + // Sometimes config.credentials is a function but only throws + // as a way of informing users that something is missing. + // That error and any other credential retrieval errors are + // not relevant for feature-checking and should be ignored. } } }