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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//! Declarative guard macros for finite/positive parameter validation.
//!
//! Two macros for the dominant *fail-loud* pattern at constructor and entry
//! boundaries:
//!
//! - [`crate::validate_finite`] panics if the value is `NaN` or `±∞`.
//! - [`crate::validate_finite_positive`] panics if the value is `NaN`, `±∞`,
//! or `<= 0`.
//!
//! ## Diagnostic-message contract (partial Fail Loudly)
//!
//! CLAUDE.md *Fail Loudly* asks every panic message to name (a) the
//! parameter, (b) the failed condition, and (c) what the caller should
//! fix. These macros emit a uniform message that delivers (a), (b), and
//! the offending value — but **not** (c). They take both the parameter
//! name *and* the call-site context as literals so the panic message
//! names the entity being constructed *and* the field being validated:
//!
//! ```text
//! <context>: <name> must be finite, got {value}
//! <context>: <name> must be finite and > 0, got {value}
//! ```
//!
//! That covers the bulk of constructor-boundary `is_finite()` /
//! `is_finite() && > 0` checks, where the remediation is structural
//! ("don't pass NaN/∞/non-positive") and the `<context>: <name>` prefix
//! already points the caller at the offending argument. Sites whose
//! correct fix is *site-specific* — e.g. "Fix the upstream parent-time
//! advance ..." or "Use 0.0 for per-step refresh ..." — should *not*
//! migrate to these macros; they should keep their hand-written
//! `assert!` with the bespoke remediation tail (see the "When *not* to
//! use these" bullets below).
//!
//! The message wording is identical to the hand-written `assert!` macros
//! it replaces at the migrated sites — call sites that already have a
//! `#[should_panic(expected = "<name> must be finite ...")]` test stay
//! green because the substring is preserved verbatim.
//!
//! ## When *not* to use these
//!
//! - **`const fn` constructors**: formatted `panic!` is not allowed in
//! `const fn` on stable Rust at our MSRV (compile-time evaluation
//! cannot allocate the formatted message buffer). `PlanetShape::new`
//! uses static-message `panic!` branches by design so the validation
//! fires at compile time on `const PLANET: PlanetShape =
//! PlanetShape::new(...)` declarations.
//! - **`Result::Err` boundaries**: validators that propagate an error rather
//! than panicking (e.g. `OrbitalElements::from_cartesian_impl` returning
//! `OrbitalError::InvalidMu`, `FrameTransform::from_matrix_validated`
//! returning `FrameTransformError::NonFinite`, `AdaptiveConfig::check`
//! returning `Result<(), &'static str>`) should keep the existing
//! conditional and `return Err(...)`. The macros panic; they cannot model
//! error-propagation.
//! - **Compound conditions other than `finite && > 0`**: a check like
//! `finite && >= 0` (zero allowed) or `finite && in [0, 1]` doesn't fit
//! either macro. Hand-write the `assert!`.
//! - **Sites whose existing message carries site-specific remediation
//! text** ("Fix the upstream parent-time advance ...", "Use 0.0 for
//! per-step refresh ...", etc.). The macros emit a uniform message
//! that intentionally omits remediation guidance (see the contract
//! above), so migrating such a site would strictly downgrade its
//! diagnostic — a Fail-Loudly regression. Leave the hand-written
//! `assert!` alone; that is the recommended pattern whenever
//! remediation is site-specific.
/// Panic if `$value` is not finite (NaN or ±∞), naming the construction
/// context and the failing parameter.
///
/// # Panics
/// Panics with the message
///
/// ```text
/// <context>: <name> must be finite, got {value}
/// ```
///
/// where `<context>` and `<name>` are the string-literal arguments and
/// `{value}` is the offending `f64`.
///
/// # Examples
/// ```should_panic
/// use astrodyn_quantities::validate_finite;
/// validate_finite!("GroundFacet::new", "alt_offset", f64::NAN);
/// // panics: "GroundFacet::new: alt_offset must be finite, got NaN"
/// ```
/// Panic if `$value` is not finite (NaN or ±∞) or not strictly positive,
/// naming the construction context and the failing parameter.
///
/// # Panics
/// Panics with the message
///
/// ```text
/// <context>: <name> must be finite and > 0, got {value}
/// ```
///
/// where `<context>` and `<name>` are the string-literal arguments and
/// `{value}` is the offending `f64`.
///
/// # Examples
/// ```should_panic
/// use astrodyn_quantities::validate_finite_positive;
/// validate_finite_positive!("SphericalTerrain::new", "radius", 0.0);
/// // panics: "SphericalTerrain::new: radius must be finite and > 0, got 0"
/// ```