Effect CommunityEC
Effect Community2y ago
17 replies
Aleks M

Handling Errors in TypeScript with Custom Error Classes and Effect Library

Here I am again asking basic questions about error handling.
Say I have the following setup
class ApplicationError extends Data.TaggedError(`ApplicationError`)<{ cause?: unknown }> {}

const someOtherFunction = async () => {
  return Promise.reject(new Error('This is an error'))
}

export const handler = () => Effect.gen(function* ($) {
  const eff = Effect.tryPromise(() => someOtherFunction())
    .pipe(
      Effect.mapError(({ error }) => new ApplicationError({ cause: error }))
    )

  yield* $(eff)
}).pipe(runPromise)

and the output i get is
Error       
|  
|  ↳ ApplicationError
|  ↳ at f (src/test-function.ts:21:38)
|  ↳ at effect@2.4.19/node_modules/effect/src/internal/core.ts:1044:35 

Can I get it to display original error and location using built-in effect facilities?
Was this page helpful?