Skip to content

Commit 52da0ee

Browse files
committed
docs: put more emphasis on returning values
1 parent 2d9d6b0 commit 52da0ee

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

apps/web/src/content/docs/v4/tutorials/modeling-errors.mdx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,15 @@ A `Promise<Authorization>` that could reject is now an
491491

492492
### Return a tagged error from a step
493493

494-
Inside `Effect.gen`, yield an error to fail the whole `Effect`, the way
495-
`throw` stops a function. The yielded error joins the `Error` type parameter,
496-
next to the `NetworkError` from the wrapped call:
494+
This line feels wrong when you first see it: a step fails by returning an error
495+
value, with no `throw` and no outer `catch`.
496+
497+
The error value is not new. `new PaymentDeclinedError()` is the same class
498+
instance you would have passed to `throw`. `throw` does not create anything.
499+
It moves the value up the call stack until a `catch` block receives it. Here,
500+
the value comes back the same way a success does, and the rest of the `Effect`
501+
stops. The error joins `NetworkError` in the `Error` type parameter, where
502+
TypeScript sees it:
497503

498504
```ts twoslash
499505
import { Effect, Data } from "effect"

0 commit comments

Comments
 (0)