MCPcopy Index your code
hub / github.com/simstudioai/sim / withS3ErrorContext

Function withS3ErrorContext

apps/sim/lib/data-drains/destinations/s3.ts:142–159  ·  view source on GitHub ↗

* Surfaces actionable S3 SDK error codes (`AccessDenied`, `NoSuchBucket`, * `InvalidAccessKeyId`, `SignatureDoesNotMatch`, ...) and preserves the * original error as `cause` so callers can still branch on `code`/`$metadata`.

(action: string, fn: () => Promise<T>)

Source from the content-addressed store, hash-verified

140 * original error as `cause` so callers can still branch on `code`/`$metadata`.
141 */
142async function withS3ErrorContext<T>(action: string, fn: () => Promise<T>): Promise<T> {
143 try {
144 return await fn()
145 } catch (error) {
146 if (isS3ServiceException(error)) {
147 const code = error.name
148 const status = error.$metadata?.httpStatusCode
149 const requestId = error.$metadata?.requestId
150 logger.warn('S3 operation failed', { action, code, status, requestId })
151 /** Preserve SDK error as `cause` so callers can still branch on `code` / `$metadata`. */
152 throw new Error(
153 `S3 ${action} failed (${code}${status ? ` ${status}` : ''}): ${error.message}`,
154 { cause: error }
155 )
156 }
157 throw error
158 }
159}
160
161export const s3Destination: DrainDestination<S3DestinationConfig, S3DestinationCredentials> = {
162 type: 's3',

Callers 2

testFunction · 0.85
deliverFunction · 0.85

Calls 3

isS3ServiceExceptionFunction · 0.85
warnMethod · 0.65
fnFunction · 0.50

Tested by 1

testFunction · 0.68