Ergonomics of producing a deliberate Defect
Summary
Design discussion: producing a deliberate Defect — short-circuiting a chain into the Defect channel for a known condition — is currently awkward, and it's not obvious what the blessed idiom is.
Motivation — real-world evidence
At an inbound HTTP boundary that folds a Defect to a 500, a known-technical precondition (a required config value is missing) must surface as a Defect. The only way found to mint that Defect was:
return fromThrowable(
() => { throw new Error("required config value is missing"); },
(cause, defect) => defect(cause),
)().toAsync();
That's a lot of ceremony (throw-inside-a-thunk + throwaway qualify + toAsync) for "this is a defect, put it in the Defect channel."
Constraint
This is deliberately in tension with Thesis #3 / the no-Defect-constructor rule: defects are supposed to arise only at boundaries, and there's intentionally no public Defect(...) constructor. So this issue is a design question, not a request to just add a constructor.
Options to weigh
- Do nothing but document a canonical idiom (and shorten it via
fromSafeThrowable(see #76):fromSafeThrowable(() => { throw e })().toAsync()). - A narrow, honestly-named boundary helper — e.g. something that replays a known cause through the
fromThrowableboundary (the same mechanism@unthrown/effect'sfromExitalready uses to mint a Defect from Effect'sdie). Naming should make clear it's a boundary, not a general constructor. - Explicitly decide it stays awkward on purpose and just document why, so future readers understand it's intentional friction.
Leaning toward (1) + a decision recorded in the guide, but opening for discussion.