Hello! I've been developing a lightweight tool to detect, alert, and log whenever a fatal condition has occurred. I'm sharing it here today in case it's useful for your own projects.
I started this as a utility for my own project because I wanted two things:
- Visibility Alert users with a fatal popup/dialog instead of silent crashes
- Reliability Be able to reliably save unresolved traces that can then be resolved later given original debug files.
I wanted this without adding heavy dependencies or injections.
fault is a Linux and Windows library for C and C++ users, implemented in C++20. Key features:- Broad coverage Handles POSIX signals, Windows SEH exceptions, std::terminate, as well as having explicit
panic and panic-based assertions- Signal-safe by default: Prioritizes logging unresolved, safe traces within POSIX signal handlers. Safe trace cannot be written? If the user permits,
fault will perform a best-effort attempt to do a regular trace while imposing safeguards against deadlocks and recursive signals.- Concurrency Resilient: If multiple threads trigger a fatal condition simultaneously,
fault ensures only the first one enters the mechanism. It prevents the system from shutting down prematurely during the microseconds needed to log and display the report or popup.- Panic and Modern C++ assertions, backed with
fault unified handling. Includes FAULT_ASSERT, fault::panic, fault::expect, with support for customizable strings, formatted arguments, and deferred callables. Wether debug only or also release, and wether you'll want source location or not, there's an equivalent expression present.- Cpptrace integration: Whereas hidden by default, if you use
cpptrace, fault can automatically log propagated traces from exceptions and saved requested traces whenever a panic or std::terminate trigger.Additional Utilities:
- Explicit shutdown request API (atomics-backed).
- Automated optional handling for
SIGINT / SIGTERM- A Python script to resolve traces using
addr2lineLink to repo: GitHub
fault is a work in progress (v0.1.2), and new features may happen in the coming weeks. Feedback is appreciated.https://redd.it/1qbyaca
@r_cpp