barrel_lib (barrel_docdb v1.0.0)
View SourceSmall shared helpers for wrapping try ... catch ... end idioms that recur across barrel_docdb, so the pattern lives in one place.
Summary
Functions
Run Fun, returning Default on any exception. Best-effort calls where a failure should fall back to a fixed value.
Run Fun, capturing any failure as {error, {Class, Reason, Stack}}. Used to ship worker results back without crashing the caller.
Run a fold that early-terminates by throwing {stop, Result}. The fold's callback throws {stop, Acc} to stop iteration; this returns either the fold's normal result or the thrown accumulator.
Functions
-spec safe(fun(() -> Result), Default) -> Result | Default.
Run Fun, returning Default on any exception. Best-effort calls where a failure should fall back to a fixed value.
Run Fun, capturing any failure as {error, {Class, Reason, Stack}}. Used to ship worker results back without crashing the caller.
-spec safe_fold(fun(() -> Result)) -> Result.
Run a fold that early-terminates by throwing {stop, Result}. The fold's callback throws {stop, Acc} to stop iteration; this returns either the fold's normal result or the thrown accumulator.