result.unwrap
The value of a success, or a thrown KernelDiagnosticError carrying the failure’s first error.
Usage
Result.unwrap<T>(r: Result<T>): TParameters
rResult<T>The result to read.
Returns
The success value; for a failure it does not return but throws.
Errors
Guarantees
- on success it returns r.value (===)
- on failure the thrown error is a KernelDiagnosticError whose diagnostic is Result.error(r) (e.diagnostic.code === Result.error(r).code)
Use instead
result.valueOr: a fallback value is acceptable and no exception is wanted
Example
Result.unwrap(Result.ok(3)) // → 3
let code; try { Result.unwrap(Result.fail('GEOMETRY_INPUT_INVALID', 'bad radius')) } catch (e) { code = e.diagnostic.code }
code // → 'GEOMETRY_INPUT_INVALID'