Effect CommunityEC
Effect Community13mo ago
3 replies
gavriguy

Why an Effect.tryPromise with a catch statement is considered an error

In the following code (https://effect.website/play/#ac4d32d838c3) the program exists on the tryPromise although I catch it. How can I recover from a failed promise and continue running the program?

import { NodeRuntime } from "@effect/platform-node"
import { Effect } from "effect"
import { DevToolsLive } from "./DevTools"

const program = Effect.gen(function*() {
  yield* Effect.log("Welcome to the Effect Playground!")
  yield* Effect.tryPromise({
    try: () => Promise.reject("la la la"),
    // catch: (e) => new Error(`something went wrong ${e}`),
    catch: (e) => Effect.succeed(`something went wrong`)
  })
  yield* Effect.log("after")
}).pipe(Effect.withSpan("program", {
  attributes: { source: "Playground" }
}))

program.pipe(
  Effect.provide(DevToolsLive),
  NodeRuntime.runMain
)
Effect Documentation
Was this page helpful?