scirs2_core/physics/error.rs
1//! Error types for the physics module.
2
3use thiserror::Error;
4
5/// Errors that can arise from physics computations.
6#[derive(Debug, Clone, PartialEq, Error)]
7pub enum PhysicsError {
8 /// A physical parameter had an invalid value (e.g. negative mass).
9 #[error("Invalid parameter '{param}': {reason}")]
10 InvalidParameter {
11 /// Name of the parameter.
12 param: &'static str,
13 /// Human-readable explanation.
14 reason: String,
15 },
16
17 /// The requested quantum number is out of range.
18 #[error("Quantum number out of range: {0}")]
19 QuantumNumberOutOfRange(String),
20
21 /// The velocity is at or exceeds the speed of light (relativistic singularity).
22 #[error("Velocity {velocity:.6e} m/s is >= speed of light {c:.6e} m/s")]
23 SuperluminalVelocity {
24 /// Supplied velocity (m/s).
25 velocity: f64,
26 /// Speed of light (m/s).
27 c: f64,
28 },
29
30 /// A general domain error (argument outside the domain of the function).
31 #[error("Domain error: {0}")]
32 DomainError(String),
33}
34
35/// Convenience result alias for physics functions.
36pub type PhysicsResult<T> = Result<T, PhysicsError>;