Skip to main content

yf_options/
error.rs

1//! Error types for yf-options
2//!
3//! Re-exports yf-common errors with tool-specific additions.
4
5use thiserror::Error;
6use yf_common::error::YfCommonError;
7
8/// Tool-specific errors for yf-options
9#[derive(Error, Debug)]
10pub enum YfOptionsError {
11    /// Common library error (wraps all yf-common errors)
12    #[error(transparent)]
13    Common(#[from] YfCommonError),
14
15    /// Invalid strike range format
16    #[error("Invalid strike range format: {0}")]
17    StrikeRangeError(String),
18
19    /// No options data found
20    #[error("No options data found for symbol {0}")]
21    NoDataError(String),
22
23    /// API returned error
24    #[error("API returned error: {0}")]
25    ApiError(String),
26
27    /// Greeks calculation error
28    #[error("Greeks calculation error: {0}")]
29    #[allow(dead_code)] // Public API - may be used by library consumers
30    GreeksError(String),
31}
32
33pub type Result<T> = std::result::Result<T, YfOptionsError>;
34
35// Convenience conversions so `?` works seamlessly with common error sources
36impl From<std::io::Error> for YfOptionsError {
37    fn from(err: std::io::Error) -> Self {
38        YfOptionsError::Common(YfCommonError::IoError(err))
39    }
40}
41
42impl From<serde_json::Error> for YfOptionsError {
43    fn from(err: serde_json::Error) -> Self {
44        YfOptionsError::Common(YfCommonError::JsonError(err))
45    }
46}
47
48impl From<reqwest::Error> for YfOptionsError {
49    fn from(err: reqwest::Error) -> Self {
50        YfOptionsError::Common(YfCommonError::RequestError(err))
51    }
52}