Skip to main content

argmin/core/
errors.rs

1// Copyright 2018-2024 argmin developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7
8//! # Errors
9
10use thiserror::Error;
11
12/// Argmin error type
13#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum ArgminError {
16    /// Indicates and invalid parameter
17    #[error("Invalid parameter: {text:?}")]
18    InvalidParameter {
19        /// Text
20        text: String,
21    },
22
23    /// Indicates that a function is not implemented
24    #[error("Not implemented: {text:?}")]
25    NotImplemented {
26        /// Text
27        text: String,
28    },
29
30    /// Indicates that a function is not initialized
31    #[error("Not initialized: {text:?}")]
32    NotInitialized {
33        /// Text
34        text: String,
35    },
36
37    /// Indicates that a condition is violated
38    #[error("Condition violated: {text:?}")]
39    ConditionViolated {
40        /// Text
41        text: String,
42    },
43
44    /// Checkpoint was not found
45    #[error("Checkpoint not found: {text:?}")]
46    CheckpointNotFound {
47        /// Text
48        text: String,
49    },
50
51    /// For errors which are likely bugs.
52    #[error("Potential bug: {text:?}. This is potentially a bug. Please file a report on https://github.com/argmin-rs/argmin/issues")]
53    PotentialBug {
54        /// Text
55        text: String,
56    },
57
58    /// Indicates an impossible error
59    #[error("Impossible Error: {text:?}")]
60    ImpossibleError {
61        /// Text
62        text: String,
63    },
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    send_sync_test!(error, ArgminError);
71}