use alloy::{
contract::Error as ContractError,
transports::{RpcError, TransportErrorKind},
};
use eigensdk::{
client_avsregistry::error::AvsRegistryError, crypto_bls::error::BlsError,
services_blsaggregation::bls_aggregation_service_error::BlsAggregationServiceError as EigensdkBlsAggregationServiceError,
services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceError,
};
use newton_prover_chainio::{bls::BlsAggregationServiceError, error::ChainIoError};
use newton_prover_core::config::error::ConfigError;
use serde_json::Error;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum AggregatorError {
#[error("Key error: {0}")]
KeyError(String),
#[error("Bls Aggregation Service Error : {0}")]
BlsAggregationServiceError(#[from] EigensdkBlsAggregationServiceError),
#[error("Task Response not found")]
TaskResponseNotFound,
#[error("Config parse error")]
ParseError(#[from] ConfigError),
#[error("Failed to build avs registry chain reader ")]
BuildAvsRegistryChainReader(#[from] AvsRegistryError),
#[error("Failed to build avs wrtier in chain io ")]
BuildAvsWriter(#[from] ChainIoError),
#[error("Bls Crate Error SDK")]
Bls(#[from] BlsError),
#[error("Alloy rpc error")]
AlloyRpc(#[from] RpcError<TransportErrorKind>),
#[error("Serde json error")]
SerdeError(#[from] Error),
#[error("IO error")]
IOError(#[from] std::io::Error),
#[error("Operator Info Service error")]
OperatorInfoServiceError(#[from] OperatorInfoServiceError),
#[error("Alloy Contract Error")]
ContractError(#[from] ContractError),
#[error("Invalid Bls Key")]
InvalidBlsKey(String),
#[error("Send aggregated response error")]
SendAggregatedResponseError,
}
#[derive(Debug, Error)]
pub enum AggregatorCoreError {
#[error("Invalid timeout duration: {0}")]
InvalidTimeoutDuration(String),
#[error("Aggregation service error: {0}")]
AggregationServiceError(#[from] BlsAggregationServiceError),
#[error("Timeout waiting for aggregation after {duration_ms} ms (timeout: {timeout_ms} ms)")]
Timeout {
duration_ms: u128,
timeout_ms: u128,
operator_errors: Option<Vec<crate::rpc_server::OperatorErrorResponse>>,
},
#[error("Task {task_id} not initialized - call initialize_task first")]
TaskNotInitialized {
task_id: newton_prover_core::TaskId,
},
#[error("Operation cancelled")]
Cancelled,
}