Skip to main content

SurfaceError

Enum SurfaceError 

Source
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

§reason: &'static str

A reference to a static string that explains the reason for an error or a condition.

§

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.

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 SurfaceError type.
  • The constructed errors leverage the OperationErrorKind to ensure structured and detailed error categorization.
Source

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 SurfaceError containing a NotSupported operation error.
  • 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.
Source

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 SurfaceError containing an InvalidParameters operation error.
  • 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.

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 operation field is hardcoded as "Position" to indicate the context of the error (i.e., relating to position management).
  • The reason field is derived from the to_string representation of the PositionError, ensuring a human-readable explanation.
§Example Integration:
  1. If a PositionError is encountered during curve calculations, this implementation converts it into a SurfaceError for consistent error handling within the curves module.
  2. The generated SurfaceError provides detailed diagnostic information about the reason for the failure, enabling effective debugging.
§Implementation Notes:
  • This conversion leverages the OperationErrorKind::InvalidParameters variant 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 SurfaceError domain 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.

Source

pub fn generator<E>(error: E) -> Self
where E: Error + Send + Sync + 'static,

Wraps a caller-supplied parametric generator failure, keeping the original error reachable as the variant’s source.

Trait Implementations§

Source§

impl Debug for SurfaceError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SurfaceError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for SurfaceError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<InterpolationError> for SurfaceError

Source§

fn from(err: InterpolationError) -> Self

Converts to this type from the input type.
Source§

impl From<OptionsError> for SurfaceError

Source§

fn from(source: OptionsError) -> Self

Converts to this type from the input type.
Source§

impl From<PositionError> for SurfaceError

Source§

fn from(source: PositionError) -> Self

Converts to this type from the input type.
Source§

impl From<SurfaceError> for InterpolationError

Source§

fn from(source: SurfaceError) -> Self

Converts to this type from the input type.
Source§

impl From<SurfaceError> for MetricsError

Source§

fn from(source: SurfaceError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more