Handling Failed `release` in `acquireUseRelease` for AWS SDK Resource Management

Is there a pattern or mechanism for handling a failed release in
acquireUseRelease
? I am trying to use the aws-sdk on to update resources in multiple accounts. This means getting the creds for each account, attaching a permissions policy, and then detaching the permissions policy when Im done. Seems like a pretty straightforward
acquireUseRelease
situation. But I'd like more visibility beyond an error log if something fails in the detach permissions part, which happens in the release.

// Gets the creds for accountNumber, attaches appropriate permissions then
// returns the credentials ill need in the doStuffWith function 
const acquireResources =(accountNumber: string) => pipe(
  getCreds(accountNumber),
  Effect.andThen(attachPermissionsandReturnCreds)
)

const program = pipe(
  Effect.succeed([account1, account2, account3])
  Effect.andThen(Array.map((accountNumber) =>
    pipe(
      Effect.acquireUseRelease(
        acquireResources(accountNumber),
        creds => doStuffWith(creds), // returns ({ accountNumber, status: 'success' })
        creds => Effect.orElseSucceed( //The release arg must succeed
          detachPolicy(creds),
          () => Effect.void
        )
      )
    )
  )
  Effect.andThen(Effect.allWith({ mode: 'either', concurrency: 'unbounded' }))
)

const output = await Effect.runPromise(configured);
console.log(util.inspect(output, { depth: null }


So lets says accounts 1/2/3 are on fibers 1/2/3 respectively, and account#2 is the one that fails to detach. I have a log of the successful doStuff on fiber 2. Then when it goes to detach ill get the logged error that it failed, but the rest of the pipe got the successful results from doStuff, which makes sense.

So I figure theres probably 3 possibilities here. 1: My only option is to manually check my logs for this unlikely occurrence. 2: There is a pattern or tool to solve this. 3: Im just doing this all wrong and shouldn't be relying on acquireUseRelease.
Was this page helpful?