libero/trace
Panic-catching + trace_id primitives for the dispatch layer.
try_call(action) runs a zero-arg function inside an Erlang
try/catch and returns Ok(result) on success or Error(reason)
where reason is the stringified exception. Throws and errors
are caught; exit signals propagate normally so process lifecycle
is not suppressed.
new_trace_id() returns a short unique string built from a
monotonic counter and system time, suitable for correlating log
lines with RPC error responses. Unique enough for debugging;
not cryptographically random.
Logging is intentionally not part of this module. Libero stays
free of wisp/logging dependencies so it can be used in any
Erlang-target consumer. The generated dispatch code uses
io.println_error as a default logger; consumers that want
structured logging can wrap the primitives in their own module.
Values
pub fn new_trace_id() -> String
Generate a unique trace id for log correlation. Uses
erlang:unique_integer on Erlang and a counter + Date.now() on
JavaScript. Unique enough for debugging; not cryptographically
random.
pub fn try_call(action: fn() -> a) -> Result(a, String)
Run the given function, catching throws and errors (not exits).
Returns the result on success; on failure, returns the stringified
exception reason. Callers typically pair this with a trace id from
new_trace_id and log both under a single correlation id.
nolint: stringly_typed_error – wraps OTP catch; exception reason is inherently a string