1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: Apache-2.0
//! The `fail_point!` and `fail_point_err!` injection macros.
//!
//! Each takes the scope the point is evaluated in as its first argument. A
//! call site with a node identity passes `FailScope::Node(id)`. The form
//! without a scope evaluates in `FailScope::Any`, for code with no node
//! identity. Without the calling crate's `failpoints` feature, a scoped form
//! only type-checks its scope and evaluates no name.
/// Inject a fail point. Does nothing at runtime without the `failpoints`
/// feature.
///
/// Usage in production code:
/// `nodedb_types::fail_point!(scope, "calvin_static::during_overlay_stage");`
/// `nodedb_types::fail_point!("wal::roll_before_seal");` (no node identity)
///
/// Tests opt in by enabling the feature and arming actions:
/// `FailGuard::for_node(node_id, "calvin_static::during_overlay_stage",
/// FailAction::Panic);`
/// Inject a fail point that can abort the enclosing function with an error.
///
/// `$map` receives the detail string armed with `FailAction::Fail` and
/// returns the error value to propagate, so each crate injects its own error
/// type without the framework knowing about it:
///
/// ```ignore
/// fail_point_err!("wal::flush_out_of_space", |_| WalError::OutOfSpace {
/// context: "WAL segment append (failpoint)",
/// });
/// fail_point_err!(FailScope::Node(node_id), "cut_floor::before_persist", |detail| {
/// Error::Internal { detail }
/// });
/// ```
///
/// Does nothing at runtime without the `failpoints` feature.