Skip to main content

omnigraph/
failpoints.rs

1use crate::error::Result;
2
3pub(crate) fn maybe_fail(_name: &str) -> Result<()> {
4    #[cfg(feature = "failpoints")]
5    {
6        let name = _name;
7        fail::fail_point!(name, |_| {
8            return Err(crate::error::OmniError::manifest(format!(
9                "injected failpoint triggered: {}",
10                name
11            )));
12        });
13    }
14    Ok(())
15}
16
17#[cfg(feature = "failpoints")]
18pub struct ScopedFailPoint {
19    name: String,
20}
21
22#[cfg(feature = "failpoints")]
23impl ScopedFailPoint {
24    pub fn new(name: &str, action: &str) -> Self {
25        fail::cfg(name, action).expect("configure failpoint");
26        Self {
27            name: name.to_string(),
28        }
29    }
30}
31
32#[cfg(feature = "failpoints")]
33impl Drop for ScopedFailPoint {
34    fn drop(&mut self) {
35        fail::remove(&self.name);
36    }
37}