Result Helpers
Result helpers provide a structured, predictable alternative to exceptions. Instead of throwing, they return explicit success or failure objects that make control flow impossible to ignore. Result helpers never mutate input, never throw, and never rely on JavaScript’s exception system. They give you a uniform way to represent outcomes across normalization, validation, parsing, and domain logic.
A result is always one of two shapes:
- Success: Containing a typed value.
- Failure: Containing structured error information.
Error helpers complement result helpers by providing a consistent, serializable way to construct and detect error objects. Together, they form the foundation of Jane’s clarity‑first error‑handling model.
Available Result & Error Helpers
Result and error helpers are grouped by the kind of behavior they support:
Construction
- ok — Create a typed success result.
- error — Create a structured failure result.
- createError — Construct a normalized, serializable error object with a consistent shape.
Detection
- isErrorLike — Determine whether a value matches Jane’s error‑object shape.
Unwrapping
- unwrap — Extract the value from a success result or return a rejected Promise on failure.
- unwrapOr — Extract the value or fall back to a default without throwing.
Safe execution
- safeTry — Execute a function and capture success or failure as a result object. Each helper is small, focused, and designed to be combined with others to build expressive, defensive flows.
When to Use Result & Error Helpers
Use result and error helpers when:
- You want to avoid exceptions entirely and rely on explicit success/failure values.
- You need predictable, structured error information instead of thrown errors.
- You want to compose multiple operations that may fail without nested try/catch.
- You want to make failure handling explicit and visible in your code.
- You need a safe, typed alternative to exception‑driven control flow.
- You want to normalize error shapes coming from external libraries or unknown sources.
Result helpers help you build systems where every outcome is intentional and accounted for. Error helpers ensure that all failures share the same shape, semantics, and clarity‑first philosophy.
Why Result & Error Helpers Matter
Result and error helpers form a core layer of Jane’s runtime model: type guards → normalizers → functional helpers → result helpers → validators → parsers
- Type guards tell you what a value is.
- Normalizers tell you what shape it should be.
- Functional helpers structure the logic that connects these steps.
- Result helpers capture success or failure explicitly.
- Error helpers ensure failures are structured, serializable, and consistent.
- Validators tell you whether it’s acceptable.
- Parsers combine everything into a typed result.
Result and error helpers are the backbone of Jane’s error‑handling philosophy. They replace exceptions with structured, predictable outcomes, making your pipelines safer, clearer, and more maintainable. They ensure that every failure is explicit, typed, and handled intentionally — never hidden behind thrown errors.