|
1 |
| -use snafu::Snafu; |
| 1 | +use thiserror::Error as ThisError; |
2 | 2 |
|
3 | 3 | /// An error structure that contains error variants that occur when building a model.
|
4 |
| -#[derive(Debug, Clone, Snafu, PartialEq, Eq)] |
5 |
| -#[snafu(visibility(pub))] |
| 4 | +#[derive(Debug, Clone, PartialEq, Eq, ThisError)] |
6 | 5 | pub enum ModelBuildError {
|
7 | 6 | /// Model or function parameters contain duplicates
|
8 |
| - #[snafu(display("Parameter list {:?} contains duplicates! Parameter lists must comprise only unique elements.",function_parameters))] |
9 |
| - DuplicateParameterNames { function_parameters: Vec<String> }, |
| 7 | + #[error("Parameter list {:?} contains duplicates! Parameter lists must comprise only unique elements.",function_parameters)] |
| 8 | + DuplicateParameterNames { |
| 9 | + /// the given parameter list containing duplicates |
| 10 | + function_parameters: Vec<String>, |
| 11 | + }, |
10 | 12 |
|
11 | 13 | /// Model or function parameter list is empty. To add functions that are independent of
|
12 | 14 | /// model parameters, use the interface for adding invariant functions.
|
13 |
| - #[snafu(display( |
| 15 | + #[error( |
14 | 16 | "A function or model parameter list is empty! It must at least contain one parameter."
|
15 |
| - ))] |
| 17 | + )] |
16 | 18 | EmptyParameters,
|
17 | 19 |
|
18 | 20 | /// A function was added to the model which depends on parameters which are not in the model
|
19 |
| - #[snafu(display( |
| 21 | + #[error( |
20 | 22 | "Function parameter '{}' is not part of the model parameters.",
|
21 | 23 | function_parameter
|
22 |
| - ))] |
23 |
| - FunctionParameterNotInModel { function_parameter: String }, |
| 24 | + )] |
| 25 | + FunctionParameterNotInModel { |
| 26 | + /// the name of the parameter not in the set |
| 27 | + function_parameter: String, |
| 28 | + }, |
24 | 29 |
|
25 | 30 | /// Tried to provide a partial derivative with respect to a parameter that a function does
|
26 | 31 | /// not depend on
|
27 |
| - #[snafu(display( |
| 32 | + #[error( |
28 | 33 | "Parameter '{}' given for partial derivative does not exist in parameter list '{:?}'.",
|
29 | 34 | parameter,
|
30 | 35 | function_parameters
|
31 |
| - ))] |
| 36 | + )] |
32 | 37 | InvalidDerivative {
|
| 38 | + /// paramter where a derivative was provided |
33 | 39 | parameter: String,
|
| 40 | + /// the actual parameters this function depends on |
34 | 41 | function_parameters: Vec<String>,
|
35 | 42 | },
|
36 | 43 |
|
37 | 44 | /// Tried to provide the same partial derivative twice.
|
38 |
| - #[snafu(display("Derivative for parameter '{}' was already provided! Give each partial derivative exactly once.", parameter))] |
39 |
| - DuplicateDerivative { parameter: String }, |
| 45 | + #[error("Derivative for parameter '{}' was already provided! Give each partial derivative exactly once.", parameter)] |
| 46 | + DuplicateDerivative { |
| 47 | + /// the name of the derivative specified twice |
| 48 | + parameter: String, |
| 49 | + }, |
40 | 50 |
|
41 | 51 | /// Not all partial derivatives for a function where given. Each function must be given
|
42 | 52 | /// a partial derivative with respect to each parameter it depends on.
|
43 |
| - #[snafu(display( |
| 53 | + #[error( |
44 | 54 | "Function with paramter list {:?} is missing derivative for parametr '{}'.",
|
45 | 55 | function_parameters,
|
46 | 56 | missing_parameter
|
47 |
| - ))] |
| 57 | + )] |
48 | 58 | MissingDerivative {
|
| 59 | + /// this parameter misses a derivative |
49 | 60 | missing_parameter: String,
|
| 61 | + /// the parameters that this function depends on |
50 | 62 | function_parameters: Vec<String>,
|
51 | 63 | },
|
52 | 64 |
|
53 | 65 | /// Tried to construct a model without base functions
|
54 |
| - #[snafu(display( |
| 66 | + #[error( |
55 | 67 | "Tried to construct model with no functions. A model must contain at least one function."
|
56 |
| - ))] |
| 68 | + )] |
57 | 69 | EmptyModel,
|
58 | 70 |
|
59 | 71 | /// The model depends on a certain parameter that none of the base functions depend on.
|
60 |
| - #[snafu(display("Model depends on parameter '{}', but none of its functions use it. Each model parameter must occur in at least one function.",parameter))] |
61 |
| - UnusedParameter { parameter: String }, |
| 72 | + #[error("Model depends on parameter '{}', but none of its functions use it. Each model parameter must occur in at least one function.",parameter)] |
| 73 | + UnusedParameter { |
| 74 | + /// the unused parameter name |
| 75 | + parameter: String, |
| 76 | + }, |
62 | 77 |
|
63 | 78 | /// This error indicates that the more or fewer string parameters where provided as function
|
64 | 79 | /// parameters than the actual variadic function takes. This might accidentally happen when giving
|
65 | 80 | /// a derivative that does not depend on a certain parameter, whereas the base function does.
|
66 | 81 | /// However, the library requires that the derivatives take all the parameters its base function
|
67 | 82 | /// takes in the same order.
|
68 |
| - #[snafu(display( |
| 83 | + #[error( |
69 | 84 | "Incorrect parameter count: Given function parameters '{:?}' have length {}, but the provided function takes {} parameter arguments.",
|
70 | 85 | params,
|
71 | 86 | string_params_count,
|
72 | 87 | function_argument_count,
|
73 |
| - ))] |
| 88 | + )] |
74 | 89 | IncorrectParameterCount {
|
| 90 | + /// the parameters that the function actually depends on |
75 | 91 | params: Vec<String>,
|
| 92 | + /// the number of parameters provided through the string api |
76 | 93 | string_params_count: usize,
|
| 94 | + /// the number of arguments this function actually takes |
77 | 95 | function_argument_count: usize,
|
78 | 96 | },
|
79 | 97 |
|
80 | 98 | /// Parameter names may not contain a comma separator, because this is most likely caused by a typo, i.e.
|
81 | 99 | /// `["tau,phi"]`, instead of actually `["tau","phi"]`. So this is forbidden in order to help spotting these
|
82 | 100 | /// hard to find errors.
|
83 |
| - #[snafu(display("Parameter names may not contain comma separator: '{}'. Did you want to give two parameters?",param_name))] |
84 |
| - CommaInParameterNameNotAllowed { param_name: String }, |
| 101 | + #[error("Parameter names may not contain comma separator: '{}'. Did you want to give two parameters?",param_name)] |
| 102 | + CommaInParameterNameNotAllowed { |
| 103 | + /// the parameter name |
| 104 | + param_name: String, |
| 105 | + }, |
85 | 106 | }
|
0 commit comments