Skip to main content

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::StateParameter;
20pub use crate::md::TargetingError;
21use crate::{cosmic::AstroError, io::ConfigError};
22use crate::{md::trajectory::TrajError, propagators::PropagationError};
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("Covariance is not positive semi definite"))]
32    CovarianceMatrixNotPsd,
33    #[snafu(display("Could not read file: {msg}"))]
34    FileUnreadable {
35        msg: String,
36    },
37    #[snafu(display("No state data: {msg}"))]
38    NoStateData {
39        msg: String,
40    },
41    #[snafu(display("Happens when trying to modify a polynomial's (error)-th error but the polynomial has less orders than that"))]
42    PolynomialOrderError {
43        order: usize,
44    },
45    #[snafu(display("Monte Carlo error: {msg}"))]
46    MonteCarlo {
47        msg: String,
48    },
49    #[snafu(display("CCSDS error: {msg}"))]
50    CCSDS {
51        msg: String,
52    },
53    #[snafu(display("Trajectory error: {source}"))]
54    Trajectory {
55        source: TrajError,
56    },
57    #[snafu(display("Guidance law config error: {msg}"))]
58    GuidanceConfigError {
59        msg: String,
60    },
61    #[snafu(display("Config error: {source}"))]
62    ConfigError {
63        source: ConfigError,
64    },
65    #[snafu(display("issue due to Almanac: {action} {source}"))]
66    FromAlmanacError {
67        #[snafu(source(from(AlmanacError, Box::new)))]
68        source: Box<AlmanacError>,
69        action: &'static str,
70    },
71    FromPropError {
72        source: PropagationError,
73    },
74}
75
76impl From<TrajError> for NyxError {
77    fn from(source: TrajError) -> Self {
78        NyxError::Trajectory { source }
79    }
80}
81
82impl From<ConfigError> for NyxError {
83    fn from(source: ConfigError) -> Self {
84        NyxError::ConfigError { source }
85    }
86}
87
88#[derive(Debug, PartialEq, Snafu)]
89#[snafu(visibility(pub(crate)))]
90pub enum StateError {
91    #[snafu(display("{param} is unavailable in this context"))]
92    Unavailable { param: StateParameter },
93    #[snafu(display("{param} is read only in this context"))]
94    ReadOnly { param: StateParameter },
95    #[snafu(display("{param} computation caused {source}"))]
96    StateAstroError {
97        param: StateParameter,
98        source: AstroError,
99    },
100    #[snafu(display("No thruster attached to spacecraft"))]
101    NoThrusterAvail,
102}
103
104#[derive(Debug, PartialEq, Snafu)]
105#[snafu(visibility(pub(crate)))]
106pub enum EventError {
107    #[snafu(display("during event computation: {source}"))]
108    EventAlmanacError {
109        #[snafu(source(from(AlmanacError, Box::new)))]
110        source: Box<AlmanacError>,
111    },
112    #[snafu(display("during event computation: {source}"))]
113    EventStateError {
114        param: StateParameter,
115        source: StateError,
116    },
117    #[snafu(display("during event computation: {source}"))]
118    EventPhysicsError { source: PhysicsError },
119    #[snafu(display("when computing an event in a trajectory {source}"))]
120    EventTrajError { source: TrajError },
121    #[snafu(display("Event {event} not found between {start} and {end}"))]
122    NotFound {
123        start: Epoch,
124        end: Epoch,
125        event: String,
126    },
127}
128
129#[derive(Debug, Snafu)]
130#[snafu(visibility(pub(crate)))]
131pub enum MonteCarloError {
132    #[snafu(display("Monte Carlo caused {source}"))]
133    StateError { source: StateError },
134    #[snafu(display("for {param}, expected percentage between 0.0 and 1.0 but got {prct}"))]
135    ParamPercentage { param: StateParameter, prct: f64 },
136    #[snafu(display(
137        "could {action} because none of the Monte Carlo {num_runs} runs were successful"
138    ))]
139    NoSuccessfulRuns {
140        action: &'static str,
141        num_runs: usize,
142    },
143}
144
145#[derive(Debug, PartialEq, Snafu)]
146#[snafu(visibility(pub(crate)))]
147pub enum LambertError {
148    #[snafu(display("Lambert too close: Δν ~=0 and A ~=0"))]
149    TargetsTooClose,
150    #[snafu(display("No reasonable phi found to connect both radii"))]
151    NotReasonablePhi,
152    #[snafu(display("Use the Izzo algorithm for multi-rev transfers"))]
153    MultiRevNotSupported,
154    #[snafu(display("no feasible solution in {m} revolutions, max is {m_max}"))]
155    MultiRevNotFeasible { m: u32, m_max: u32 },
156    #[snafu(display("Izzo method failed to converge after {maxiter} iterations"))]
157    SolverMaxIter { maxiter: usize },
158}