Start here
@hulla/control
Return typed success or failure values so callers can handle expected errors before transforming the result.
On this page
@hulla/control lets a function return success or failure as a value. Return Ok with the data or Err with the problem, then let the caller check which one it received.
import { err, ok, type Result } from '@hulla/control'
function findTitle(id: string): Result<string, Error> {
return id === 'welcome' ? ok('Welcome') : err(new Error('Title not found'))
}This is useful when a failure is part of the function’s contract, such as a missing record or invalid input. If callers already expect an exception boundary, keep throwing and use tcf() to convert that boundary. For ordinary internal work with no meaningful failure case, a plain return value is simpler.
Build the config checker to combine parsing, validation, and error reporting in one small command.
| You want to… | Use |
|---|---|
| Run different code for success and failure | isOk() or isErr() |
| Produce one value from either branch | match() |
| Transform a payload and preserve its branch | map() or mapErr() |
| Need | Start here |
|---|---|
| Install the package and build a first result | Quick start |
| Construct, narrow, and inspect success or error values | Results |
| Transform values while keeping the result branch | Chaining |
| Catch exceptions and rejected promises at an explicit boundary | Attempts |
The result branch carries its own tag ('ok' or 'error' by default), so Result<string, string> remains unambiguous. Continue with the quick start to install @hulla/control and call a function that returns both outcomes.