1use borsh::{BorshDeserialize, BorshSerialize};
5use serde::{Deserialize, Serialize};
6use thiserror::Error;
7
8use crate::HeadersError;
9
10#[derive(
12 Clone, Debug, Eq, Error, PartialEq, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
13)]
14pub enum OracleError {
15 #[error("Missing required parameter: {param}")]
16 MissingParameter { param: String },
17
18 #[error("Invalid parameter '{param}': {reason}")]
19 InvalidParameter { param: String, reason: String },
20
21 #[error("Failed to decode {encoding} for parameter '{param}': {reason}")]
22 DecodeError {
23 param: String,
24 encoding: String,
25 reason: String,
26 },
27
28 #[error("Invalid URL: {reason}")]
29 InvalidUrl { reason: String },
30
31 #[error("URL validation failed: {reason}")]
32 UrlValidationError { reason: String },
33
34 #[error("HTTP request failed: {message}{}", reason.as_ref().map(|r| format!(", {}", r)).unwrap_or_default()
35 )]
36 HttpRequestFailed {
37 message: String,
38 reason: Option<String>,
39 },
40
41 #[error("HTTP {status} error: {reason}")]
42 HttpStatusError { status: u16, reason: String },
43
44 #[error("Response size exceeds maximum of {max_size} bytes")]
45 ResponseTooLarge { max_size: usize },
46
47 #[error("Request body size of {size} bytes exceeds maximum of {max_size} bytes")]
48 RequestBodyTooLarge { size: usize, max_size: usize },
49
50 #[error("Filter error: {reason}")]
51 FilterError { reason: String },
52
53 #[error("Timeout after {duration_ms}ms")]
54 Timeout { duration_ms: u64 },
55
56 #[error("All {attempts} retry attempts failed: {reason}")]
57 RetriesExhausted { attempts: u8, reason: String },
58
59 #[error("JSON parsing error: {reason}")]
60 JsonError { reason: String },
61
62 #[error("No valid data sources available")]
63 NoDataSources,
64
65 #[error("Failed to decrypt secret payload: {reason}")]
66 SecretDecryptionFailed { reason: String },
67
68 #[error("Invalid secret payload format: {reason}")]
69 InvalidSecretPayload { reason: String },
70
71 #[error("Failed to generate secret key: {reason}")]
72 SecretKeyGenerationFailed { reason: String },
73
74 #[error("Failed to encrypt secret: {reason}")]
75 SecretEncryptionFailed { reason: String },
76
77 #[error("Provided oracle output size is too small: {provided}")]
78 OracleOutputSizeTooSmall { provided: usize },
79
80 #[error("Invalid oracle duty input, err: {0}")]
81 InvalidOracleDutyInput(String),
82
83 #[error("Connection error: {reason}")]
84 ConnectionError { reason: String },
85
86 #[error("WebSocket error: {message}")]
87 WebSocketError { message: String },
88
89 #[error("DKG input validation failed: {reason}")]
91 DkgValidationError { reason: String },
92
93 #[error("DKG cryptographic operation failed ({operation}): {reason}")]
94 DkgCryptoError { operation: String, reason: String },
95
96 #[error("DKG handler not implemented: {handler}")]
97 DkgNotImplemented { handler: String },
98
99 #[error("DKG genesis failed: {reason}")]
100 DkgGenesisError { reason: String },
101
102 #[error("DKG share installation failed: {reason}")]
103 DkgInstallShareError { reason: String },
104
105 #[error("DKG share decryption (HPKE) failed for dealer {dealer_index}: {reason}")]
106 DkgDecryptionError { dealer_index: u16, reason: String },
107
108 #[error("DKG share verification failed for dealer {dealer_index}")]
109 DkgVerificationError { dealer_index: u16 },
110}
111
112impl From<HeadersError> for OracleError {
113 fn from(err: HeadersError) -> Self {
114 match err {
115 HeadersError::DecodeError {
116 param,
117 encoding,
118 reason,
119 } => Self::DecodeError {
120 param,
121 encoding,
122 reason,
123 },
124 HeadersError::JsonError { reason } => Self::JsonError { reason },
125 }
126 }
127}