Crates.io | subtale-cortex |
lib.rs | subtale-cortex |
version | 0.1.0 |
source | src |
created_at | 2023-09-14 15:12:08.645933 |
updated_at | 2023-09-14 15:12:08.645933 |
description | Crash handling for Rust applications |
homepage | https://cortex.subtale.com |
repository | https://github.com/subtalegames/cortex |
max_upload_size | |
id | 972748 |
size | 22,954 |
Cortex is a flexible crash handling solution for applications written in Rust.
use subtale_cortex::CrashHandler;
fn run_application() {
// Your application logic...
}
fn crash_handler(output: std::process::Output) {
// Handle the output of the application process when it crashes
}
fn main() {
let result = CrashHandler::with_process(run_application)
.crash_handler(crash_handler)
.full_backtrace() // Use `RUST_BACKTRACE` full in your application process
.run();
match result {
Ok(true) => .., // The application process finished successfully
Ok(false) => .., // The application process crashed, but the error was handled successfully
Err(e) => .., // An error was encountered spawning the application or when crash handling
}
}
Cortex uses the crash handling approach described in this blog post by Mason Remaley (Anthropic Studios) from March 2021.
The crash handling implementation is simple and straight forward: when the application is launched, invoke the application again as a subprocess of itself, and monitor the subprocess for non-successful exit codes.
To prevent the application from recursively invoking itself until infinity, a command argument (--cortex-child
) is used to identify whether the process is the crash handler (and so a subprocess should be invoked) or a subprocess.
For example, the first time that the application is run, Cortex identifies that the
--cortex-child
argument is not present. The application is then self-spawned as a subprocess, this time with the--cortex-child
argument included so the regular application logic (run_application()
in the example above) can start.
Cortex is free and open source. Unless explicitly noted otherwise, all code in this repository is dual-licensed under the MIT License and Apache License, Version 2.0.
This licensing approach is the de facto standard within the Rust ecosystem.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.