nyx_space/
errors.rs

1/*
2    Nyx, blazing fast astrodynamics
3    Copyright (C) 2018-onwards Christopher Rabotin <christopher.rabotin@gmail.com>
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU Affero General Public License as published
7    by the Free Software Foundation, either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Affero General Public License for more details.
14
15    You should have received a copy of the GNU Affero General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19use crate::md::trajectory::TrajError;
20use crate::md::StateParameter;
21pub use crate::md::TargetingError;
22use crate::{cosmic::AstroError, io::ConfigError};
23use anise::errors::{AlmanacError, PhysicsError};
24use hifitime::Epoch;
25use snafu::prelude::*;
26use std::convert::From;
27
28#[derive(Debug, Snafu)]
29#[snafu(visibility(pub(crate)))]
30pub enum NyxError {
31    #[snafu(display("Maximum iterations of {msg} reached"))]
32    MaxIterReached { msg: String },
33    #[snafu(display("Covariance is not positive semi definite"))]
34    CovarianceMatrixNotPsd,
35    #[snafu(display("Lambert too close: Δν ~=0 and A ~=0"))]
36    TargetsTooClose,
37    #[snafu(display("No reasonable phi found to connect both radii"))]
38    LambertNotReasonablePhi,
39    #[snafu(display("Use the Izzo algorithm for multi-rev transfers"))]
40    LambertMultiRevNotSupported,
41    #[snafu(display("Unavailable parameter {param:?}: {msg}"))]
42    StateParameterUnavailable { param: StateParameter, msg: String },
43    #[snafu(display("Could not load file: {msg}"))]
44    LoadingError { msg: String },
45    #[snafu(display("Could not read file: {msg}"))]
46    FileUnreadable { msg: String },
47    #[snafu(display("Cosm object not found: `{needle}` (available: {haystack:?})"))]
48    ObjectNotFound {
49        needle: String,
50        haystack: Vec<String>,
51    },
52    #[snafu(display("No interpolation data: {msg}"))]
53    NoInterpolationData { msg: String },
54    #[snafu(display("Invalid interpolation data: {msg}"))]
55    InvalidInterpolationData { msg: String },
56    #[snafu(display("No state data: {msg}"))]
57    NoStateData { msg: String },
58    #[snafu(display("Happens when trying to modify a polynomial's (error)-th error but the polynomial has less orders than that"))]
59    PolynomialOrderError { order: usize },
60    #[snafu(display(
61        "An objective based analysis or control was attempted, but no objective was defined"
62    ))]
63    NoObjectiveDefined,
64    #[snafu(display("This computation requires the orbit to be hyperbolic: {msg}"))]
65    NotHyperbolic { msg: String },
66    #[snafu(display("Monte Carlo error: {msg}"))]
67    MonteCarlo { msg: String },
68    #[snafu(display("CCSDS error: {msg}"))]
69    CCSDS { msg: String },
70    #[snafu(display("Error: {msg}"))]
71    CustomError { msg: String },
72    #[snafu(display("Trajectory error: {source}"))]
73    Trajectory { source: TrajError },
74    #[snafu(display("Math domain error: {msg}"))]
75    MathDomain { msg: String },
76    #[snafu(display("Guidance law config error: {msg}"))]
77    GuidanceConfigError { msg: String },
78    #[snafu(display("Config error: {source}"))]
79    ConfigError { source: ConfigError },
80    #[snafu(display("issue due to Almanac: {action} {source}"))]
81    FromAlmanacError {
82        #[snafu(source(from(AlmanacError, Box::new)))]
83        source: Box<AlmanacError>,
84        action: &'static str,
85    },
86}
87
88impl From<TrajError> for NyxError {
89    fn from(source: TrajError) -> Self {
90        NyxError::Trajectory { source }
91    }
92}
93
94impl From<ConfigError> for NyxError {
95    fn from(source: ConfigError) -> Self {
96        NyxError::ConfigError { source }
97    }
98}
99
100#[derive(Debug, PartialEq, Snafu)]
101#[snafu(visibility(pub(crate)))]
102pub enum StateError {
103    #[snafu(display("{param} is unavailable in this context"))]
104    Unavailable { param: StateParameter },
105    #[snafu(display("{param} is read only in this context"))]
106    ReadOnly { param: StateParameter },
107    #[snafu(display("{param} computation caused {source}"))]
108    StateAstroError {
109        param: StateParameter,
110        source: AstroError,
111    },
112    #[snafu(display("No thruster attached to spacecraft"))]
113    NoThrusterAvail,
114}
115
116#[derive(Debug, PartialEq, Snafu)]
117#[snafu(visibility(pub(crate)))]
118pub enum EventError {
119    #[snafu(display("during event computation: {source}"))]
120    EventAlmanacError {
121        #[snafu(source(from(AlmanacError, Box::new)))]
122        source: Box<AlmanacError>,
123    },
124    #[snafu(display("during event computation: {source}"))]
125    EventStateError {
126        param: StateParameter,
127        source: StateError,
128    },
129    #[snafu(display("during event computation: {source}"))]
130    EventPhysicsError { source: PhysicsError },
131    #[snafu(display("when computing an event in a trajectory {source}"))]
132    EventTrajError { source: TrajError },
133    #[snafu(display("Event {event} not found between {start} and {end}"))]
134    NotFound {
135        start: Epoch,
136        end: Epoch,
137        event: String,
138    },
139}
140
141#[derive(Debug, Snafu)]
142#[snafu(visibility(pub(crate)))]
143pub enum MonteCarloError {
144    #[snafu(display("Monte Carlo caused {source}"))]
145    StateError { source: StateError },
146    #[snafu(display("for {param}, expected percentage between 0.0 and 1.0 but got {prct}"))]
147    ParamPercentage { param: StateParameter, prct: f64 },
148    #[snafu(display(
149        "could {action} because none of the Monte Carlo {num_runs} runs were successful"
150    ))]
151    NoSuccessfulRuns {
152        action: &'static str,
153        num_runs: usize,
154    },
155}