|
| 1 | +use std::fmt::Debug; |
| 2 | + |
1 | 3 | use crate::defs::AddressDef;
|
2 | 4 | use alloy::{
|
3 | 5 | primitives::Address,
|
4 | 6 | transports::{
|
5 | 7 | RpcError as AlloyRpcError, TransportErrorKind, http::reqwest::header::InvalidHeaderValue,
|
6 | 8 | },
|
7 | 9 | };
|
| 10 | +use alloy_signer_aws::AwsSignerError; |
| 11 | +use aws_sdk_kms::error::SdkError; |
8 | 12 | use schemars::JsonSchema;
|
9 | 13 | use serde::{Deserialize, Serialize};
|
10 | 14 | use thirdweb_core::error::ThirdwebError;
|
@@ -242,11 +246,150 @@ pub enum EngineError {
|
242 | 246 | #[error("Thirdweb error: {message}")]
|
243 | 247 | ThirdwebError { message: String },
|
244 | 248 |
|
| 249 | + #[schema(title = "AWS KMS Error")] |
| 250 | + #[error(transparent)] |
| 251 | + #[serde(rename_all = "camelCase")] |
| 252 | + AwsKmsSignerError { |
| 253 | + #[serde(flatten)] |
| 254 | + error: SerialisableAwsSignerError, |
| 255 | + }, |
| 256 | + |
245 | 257 | #[schema(title = "Engine Internal Error")]
|
246 | 258 | #[error("Internal error: {message}")]
|
247 | 259 | InternalError { message: String },
|
248 | 260 | }
|
249 | 261 |
|
| 262 | +#[derive(thiserror::Error, Debug, Serialize, Clone, Deserialize, utoipa::ToSchema)] |
| 263 | +#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "type")] |
| 264 | +pub enum SerialisableAwsSdkError { |
| 265 | + /// The request failed during construction. It was not dispatched over the network. |
| 266 | + #[error("Construction failure: {message}")] |
| 267 | + ConstructionFailure { message: String }, |
| 268 | + |
| 269 | + /// The request failed due to a timeout. The request MAY have been sent and received. |
| 270 | + #[error("Timeout error: {message}")] |
| 271 | + TimeoutError { message: String }, |
| 272 | + |
| 273 | + /// The request failed during dispatch. An HTTP response was not received. The request MAY |
| 274 | + /// have been sent. |
| 275 | + #[error("Dispatch failure: {message}")] |
| 276 | + DispatchFailure { message: String }, |
| 277 | + |
| 278 | + /// A response was received but it was not parseable according the the protocol (for example |
| 279 | + /// the server hung up without sending a complete response) |
| 280 | + #[error("Response error: {message}")] |
| 281 | + ResponseError { message: String }, |
| 282 | + |
| 283 | + /// An error response was received from the service |
| 284 | + #[error("Service error: {message}")] |
| 285 | + ServiceError { message: String }, |
| 286 | + |
| 287 | + #[error("Other error: {message}")] |
| 288 | + Other { message: String }, |
| 289 | +} |
| 290 | + |
| 291 | +#[derive(Error, Debug, Serialize, Clone, Deserialize, utoipa::ToSchema)] |
| 292 | +#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "type")] |
| 293 | +pub enum SerialisableAwsSignerError { |
| 294 | + /// Thrown when the AWS KMS API returns a signing error. |
| 295 | + #[error(transparent)] |
| 296 | + Sign { |
| 297 | + aws_sdk_error: SerialisableAwsSdkError, |
| 298 | + }, |
| 299 | + |
| 300 | + /// Thrown when the AWS KMS API returns an error. |
| 301 | + #[error(transparent)] |
| 302 | + GetPublicKey { |
| 303 | + aws_sdk_error: SerialisableAwsSdkError, |
| 304 | + }, |
| 305 | + |
| 306 | + /// [`ecdsa`] error. |
| 307 | + #[error("ECDSA error: {message}")] |
| 308 | + K256 { message: String }, |
| 309 | + |
| 310 | + /// [`spki`] error. |
| 311 | + #[error("SPKI error: {message}")] |
| 312 | + Spki { message: String }, |
| 313 | + |
| 314 | + /// [`hex`](mod@hex) error. |
| 315 | + #[error("Hex error: {message}")] |
| 316 | + Hex { message: String }, |
| 317 | + |
| 318 | + /// Thrown when the AWS KMS API returns a response without a signature. |
| 319 | + #[error("signature not found in response")] |
| 320 | + SignatureNotFound, |
| 321 | + |
| 322 | + /// Thrown when the AWS KMS API returns a response without a public key. |
| 323 | + #[error("public key not found in response")] |
| 324 | + PublicKeyNotFound, |
| 325 | + |
| 326 | + #[error("Unknown error: {message}")] |
| 327 | + Unknown { message: String }, |
| 328 | +} |
| 329 | + |
| 330 | +impl<T: Debug> From<SdkError<T>> for SerialisableAwsSdkError { |
| 331 | + fn from(err: SdkError<T>) -> Self { |
| 332 | + match err { |
| 333 | + SdkError::ConstructionFailure(err) => SerialisableAwsSdkError::ConstructionFailure { |
| 334 | + message: format!("{:?}", err), |
| 335 | + }, |
| 336 | + SdkError::TimeoutError(err) => SerialisableAwsSdkError::TimeoutError { |
| 337 | + message: format!("{:?}", err), |
| 338 | + }, |
| 339 | + SdkError::DispatchFailure(err) => SerialisableAwsSdkError::DispatchFailure { |
| 340 | + message: format!("{:?}", err), |
| 341 | + }, |
| 342 | + SdkError::ResponseError(err) => SerialisableAwsSdkError::ResponseError { |
| 343 | + message: format!("{:?}", err), |
| 344 | + }, |
| 345 | + SdkError::ServiceError(err) => SerialisableAwsSdkError::ServiceError { |
| 346 | + message: format!("{:?}", err), |
| 347 | + }, |
| 348 | + _ => SerialisableAwsSdkError::Other { |
| 349 | + message: format!("{:?}", err), |
| 350 | + }, |
| 351 | + } |
| 352 | + } |
| 353 | +} |
| 354 | + |
| 355 | +impl From<AwsSignerError> for EngineError { |
| 356 | + fn from(err: AwsSignerError) -> Self { |
| 357 | + match err { |
| 358 | + AwsSignerError::Sign(err) => EngineError::AwsKmsSignerError { |
| 359 | + error: SerialisableAwsSignerError::Sign { |
| 360 | + aws_sdk_error: err.into(), |
| 361 | + }, |
| 362 | + }, |
| 363 | + AwsSignerError::GetPublicKey(err) => EngineError::AwsKmsSignerError { |
| 364 | + error: SerialisableAwsSignerError::GetPublicKey { |
| 365 | + aws_sdk_error: err.into(), |
| 366 | + }, |
| 367 | + }, |
| 368 | + AwsSignerError::K256(err) => EngineError::AwsKmsSignerError { |
| 369 | + error: SerialisableAwsSignerError::K256 { |
| 370 | + message: err.to_string(), |
| 371 | + }, |
| 372 | + }, |
| 373 | + AwsSignerError::Spki(err) => EngineError::AwsKmsSignerError { |
| 374 | + error: SerialisableAwsSignerError::Spki { |
| 375 | + message: err.to_string(), |
| 376 | + }, |
| 377 | + }, |
| 378 | + AwsSignerError::Hex(err) => EngineError::AwsKmsSignerError { |
| 379 | + error: SerialisableAwsSignerError::Hex { |
| 380 | + message: err.to_string(), |
| 381 | + }, |
| 382 | + }, |
| 383 | + AwsSignerError::SignatureNotFound => EngineError::AwsKmsSignerError { |
| 384 | + error: SerialisableAwsSignerError::SignatureNotFound, |
| 385 | + }, |
| 386 | + AwsSignerError::PublicKeyNotFound => EngineError::AwsKmsSignerError { |
| 387 | + error: SerialisableAwsSignerError::PublicKeyNotFound, |
| 388 | + }, |
| 389 | + } |
| 390 | + } |
| 391 | +} |
| 392 | + |
250 | 393 | impl From<vault_sdk::error::VaultError> for EngineError {
|
251 | 394 | fn from(err: vault_sdk::error::VaultError) -> Self {
|
252 | 395 | let message = match &err {
|
|
0 commit comments