result.fail

A failed result with one diagnostic built from a catalogue code.

Value helperSince 0.3.0

Usage

TypeScript
Result.fail<T = never>(code: KernelDiagnosticCode, message: string, details?: KernelDiagnosticDetails): Result<T>

Parameters

  • codeKernelDiagnosticCode

    The stable catalogue code, e.g. GEOMETRY_INPUT_INVALID.

    Required

  • messagestring

    What went wrong, for a human; codes are the contract, messages may be reworded.

    Required

  • detailsKernelDiagnosticDetails

    Where and what: paramPath, entities, measured, suggestedFixes, severity. Default {}.

Returns

{ ok: false, diagnostics: [d] } with d.code === code; the severity is the code’s catalogue default unless details.severity overrides it.

Use instead

  • result.failWith: the diagnostics already exist, e.g. passed up from a step

Example

TypeScript
Result.fail('GEOMETRY_INPUT_INVALID', 'radius must be positive').diagnostics[0].code // → 'GEOMETRY_INPUT_INVALID'

See also