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