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