barrel_lib (barrel_docdb v1.0.0)

View Source

Small 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

safe(Fun, Default)

-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.

safe_apply(Fun)

-spec safe_apply(fun(() -> Result)) -> {ok, Result} | {error, {atom(), term(), list()}}.

Run Fun, capturing any failure as {error, {Class, Reason, Stack}}. Used to ship worker results back without crashing the caller.

safe_fold(Fun)

-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.