A fail point implementation for Rust.
Fail point is a code point that are used to inject errors by users at runtime. This crate is inspired by FreeBSD's failpoints.
First, add this to your Cargo.toml
:
toml
[dependencies]
fail = "0.2"
Next, add the following code to your crate:
```rust
extern crate fail; ```
Define the fail points:
``` fn functionreturntuple() { fail_point!("name1"); }
fn functionreturnothers() -> u64 { failpoint!("name2", |r| r.mapor(2, |e| e.parse().unwrap())); 0 }
fn functionconditional(enable: bool) { failpoint!("name3", enable, |_| {}); } ```
Trigger a fail point via the environment variable:
$ FAILPOINTS=foo=panic cargo run
In unit tests:
```
fn test_foo() { fail::cfg("foo", "panic"); foo(); } ```
Before putting any fail points, you should carefully consider the consequences. A list of suggestions you should keep in mind:
Triggering a fail point via the HTTP API is planned but not implemented yet.