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