pub enum SurfaceError {
Point3DError {
reason: &'static str,
},
OperationError(OperationErrorKind),
Generator(Box<dyn Error + Send + Sync>),
ConstructionError(String),
AnalysisError(String),
Position(PositionError),
Options(OptionsError),
}Expand description
Error variants that can occur when working with surface-related operations.
This enum categorizes different types of errors that might occur when handling mathematical or geometrical surfaces, particularly in the context of pricing models, interpolation, or volatility surfaces.
§Error Categories
- Geometry errors (points in 3D space)
- Operation-specific errors
- Standard library errors
- Surface construction errors
- Analysis-related failures
This error type is designed to provide detailed context about what went wrong when working with financial or mathematical surface calculations, which is useful for debugging and error handling in financial modeling applications.
Variants§
Point3DError
Error related to 3D point calculations or validations.
This typically occurs when coordinates are invalid, out of expected range, or when mathematical operations on points fail.
Fields
OperationError(OperationErrorKind)
Error indicating a specific operation failed.
Contains detailed information about why the operation could not be completed, including whether the operation isn’t supported for the given surface type or was provided with invalid parameters.
Generator(Box<dyn Error + Send + Sync>)
A caller-supplied parametric generator failed.
ConstructionMethod::Parametric takes a closure written by the
caller, so its failure belongs to whichever layer wrote it, and the
math layer cannot name that type without depending on the layer
above. The cause therefore travels boxed: it stays reachable through
std::error::Error::source and downcastable to the original type,
instead of being flattened into a message at the construction
boundary (roadmap M1-10).
ConstructionError(String)
Error that occurred during the construction of a surface.
This is typically used when input data is valid but inconsistent or insufficient to construct a well-formed surface object.
AnalysisError(String)
Error that occurred during the analysis of a surface.
This is used when operations like finding extrema, calculating slopes, or evaluating a surface at specific points fail due to mathematical or algorithmic constraints.
Position(PositionError)
Error from position operations
Options(OptionsError)
Error from options operations
Implementations§
Source§impl SurfaceError
Provides helper methods for constructing specific variants of the SurfaceError type.
impl SurfaceError
Provides helper methods for constructing specific variants of the SurfaceError type.
These methods encapsulate common patterns of error creation, making it easier to consistently generate errors with the necessary context.
§Integration
- These methods simplify the process of creating meaningful error objects, improving readability
and maintainability of the code using the
SurfaceErrortype. - The constructed errors leverage the
OperationErrorKindto ensure structured and detailed error categorization.
Sourcepub fn operation_not_supported(operation: &str, reason: &str) -> Self
pub fn operation_not_supported(operation: &str, reason: &str) -> Self
§operation_not_supported
Constructs a SurfaceError::OperationError with an OperationErrorKind::NotSupported variant.
- Parameters:
operation(&str): The name of the operation that is not supported.reason(&str): A description of why the operation is not supported.
- Returns:
- A
SurfaceErrorcontaining aNotSupportedoperation error.
- A
- Use Cases:
- Invoked when a requested operation is not compatible with the current context.
- For example, attempting an unsupported computation method on a specific curve type.
Sourcepub fn invalid_parameters(operation: &str, reason: &str) -> Self
pub fn invalid_parameters(operation: &str, reason: &str) -> Self
§invalid_parameters
Constructs a SurfaceError::OperationError with an OperationErrorKind::InvalidParameters variant.
- Parameters:
operation(&str): The name of the operation that encountered invalid parameters.reason(&str): A description of why the parameters are invalid.
- Returns:
- A
SurfaceErrorcontaining anInvalidParametersoperation error.
- A
- Use Cases:
- Used when an operation fails due to issues with the provided input.
- For example, providing malformed or missing parameters for interpolation or curve construction.
Source§impl SurfaceError
Converts a PositionError into a SurfaceError by mapping it to an
OperationError with the InvalidParameters variant.
impl SurfaceError
Converts a PositionError into a SurfaceError by mapping it to an
OperationError with the InvalidParameters variant.
This implementation ensures a smooth transition between error types
when a PositionError is encountered within a context that operates
on the curves module. The InvalidParameters variant is used to
provide detailed information about the failed operation and the reason
for its failure.
§Details:
- The
operationfield is hardcoded as"Position"to indicate the context of the error (i.e., relating to position management). - The
reasonfield is derived from theto_stringrepresentation of thePositionError, ensuring a human-readable explanation.
§Example Integration:
- If a
PositionErroris encountered during curve calculations, this implementation converts it into aSurfaceErrorfor consistent error handling within thecurvesmodule. - The generated
SurfaceErrorprovides detailed diagnostic information about the reason for the failure, enabling effective debugging.
§Implementation Notes:
- This conversion leverages the
OperationErrorKind::InvalidParametersvariant to communicate that invalid parameters (or settings) were the root cause of failure. - Use this implementation to handle interoperability between error types in modular design contexts.
§Example Use Case:
This conversion is frequently used in scenarios where:
- A position-related error (e.g., from validation or limits) occurs during a curve operation.
- Such errors need to be mapped into the
SurfaceErrordomain to maintain consistent error handling across the library.
§Debugging:
The resulting SurfaceError will include contextual details, making it
straightforward to trace and debug the underlying issue.
Trait Implementations§
Source§impl Debug for SurfaceError
impl Debug for SurfaceError
Source§impl Display for SurfaceError
impl Display for SurfaceError
Source§impl Error for SurfaceError
impl Error for SurfaceError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<InterpolationError> for SurfaceError
impl From<InterpolationError> for SurfaceError
Source§fn from(err: InterpolationError) -> Self
fn from(err: InterpolationError) -> Self
Source§impl From<OptionsError> for SurfaceError
impl From<OptionsError> for SurfaceError
Source§fn from(source: OptionsError) -> Self
fn from(source: OptionsError) -> Self
Source§impl From<PositionError> for SurfaceError
impl From<PositionError> for SurfaceError
Source§fn from(source: PositionError) -> Self
fn from(source: PositionError) -> Self
Source§impl From<SurfaceError> for InterpolationError
impl From<SurfaceError> for InterpolationError
Source§fn from(source: SurfaceError) -> Self
fn from(source: SurfaceError) -> Self
Source§impl From<SurfaceError> for MetricsError
impl From<SurfaceError> for MetricsError
Source§fn from(source: SurfaceError) -> Self
fn from(source: SurfaceError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for SurfaceError
impl !UnwindSafe for SurfaceError
impl Freeze for SurfaceError
impl Send for SurfaceError
impl Sync for SurfaceError
impl Unpin for SurfaceError
impl UnsafeUnpin for SurfaceError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.