diff --git a/ic-agent/src/agent/agent_config.rs b/ic-agent/src/agent/agent_config.rs index 1e9916fc..accb242f 100644 --- a/ic-agent/src/agent/agent_config.rs +++ b/ic-agent/src/agent/agent_config.rs @@ -5,11 +5,15 @@ use crate::{ use std::{sync::Arc, time::Duration}; /// A configuration for an agent. - +#[derive(Debug)] pub struct AgentConfig { + /// See [`with_nonce_factory`](super::AgentBuilder::with_nonce_factory). pub nonce_factory: Arc, + /// See [`with_identity`](super::AgentBuilder::with_identity). pub identity: Arc, + /// See [`with_ingress_expiry`](super::AgentBuilder::with_ingress_expiry). pub ingress_expiry_duration: Option, + /// The [`with_transport`](super::AgentBuilder::with_transport). pub transport: Option>, } diff --git a/ic-agent/src/agent/agent_error.rs b/ic-agent/src/agent/agent_error.rs index b0b66eed..93d17cac 100644 --- a/ic-agent/src/agent/agent_error.rs +++ b/ic-agent/src/agent/agent_error.rs @@ -1,3 +1,5 @@ +//! Errors that can occur when using the replica agent. + use crate::{agent::status::Status, hash_tree::Label, RequestIdError}; use leb128::read; use std::{ @@ -6,122 +8,174 @@ use std::{ }; use thiserror::Error; +/// An error that occurred when using the agent. #[derive(Error, Debug)] pub enum AgentError { + /// The replica URL was invalid. #[error(r#"Invalid Replica URL: "{0}""#)] InvalidReplicaUrl(String), + /// The request timed out. #[error("The request timed out.")] TimeoutWaitingForResponse(), + /// The waiter was restarted without being started first. #[error("The waiter was restarted without being started first.")] WaiterRestartError(), + /// An error occurred when signing with the identity. #[error("Identity had a signing error: {0}")] SigningError(String), + /// The data fetched was invalid CBOR. #[error("Invalid CBOR data, could not deserialize: {0}")] InvalidCborData(#[from] serde_cbor::Error), + /// There was an error calculating a request ID. #[error("Cannot calculate a RequestID: {0}")] CannotCalculateRequestId(#[from] RequestIdError), + /// There was an error when de/serializing with Candid. #[error("Candid returned an error: {0}")] CandidError(Box), + /// There was an error parsing a URL. #[error(r#"Cannot parse url: "{0}""#)] UrlParseError(#[from] url::ParseError), + /// The HTTP method was invalid. #[error(r#"Invalid method: "{0}""#)] InvalidMethodError(#[from] http::method::InvalidMethod), + /// The principal string was not a valid principal. #[error("Cannot parse Principal: {0}")] PrincipalError(#[from] crate::export::PrincipalError), + /// The replica rejected the message. #[error(r#"The Replica returned an error: code {reject_code}, message: "{reject_message}""#)] ReplicaError { + /// The [reject code](https://smartcontracts.org/docs/interface-spec/index.html#reject-codes) returned by the replica. reject_code: u64, + /// The rejection message. reject_message: String, }, + /// The replica returned an HTTP error. #[error("The replica returned an HTTP Error: {0}")] HttpError(HttpErrorPayload), + /// Attempted to use HTTP authentication in a non-secure URL (either HTTPS or localhost). #[error("HTTP Authentication cannot be used in a non-secure URL (either HTTPS or localhost)")] CannotUseAuthenticationOnNonSecureUrl(), + /// The password manager returned an error. #[error("Password Manager returned an error: {0}")] AuthenticationError(String), + /// The status endpoint returned an invalid status. #[error("Status endpoint returned an invalid status.")] InvalidReplicaStatus, + /// The call was marked done, but no reply was provided. #[error("Call was marked as done but we never saw the reply. Request ID: {0}")] RequestStatusDoneNoReply(String), + /// A string error occurred in an external tool. #[error("A tool returned a string message error: {0}")] MessageError(String), + /// An error occurred in an external tool. #[error("A tool returned a custom error: {0}")] CustomError(#[from] Box), + /// There was an error reading a LEB128 value. #[error("Error reading LEB128 value: {0}")] Leb128ReadError(#[from] read::Error), + /// A string was invalid UTF-8. #[error("Error in UTF-8 string: {0}")] Utf8ReadError(#[from] Utf8Error), + /// The lookup path was absent in the certificate. #[error("The lookup path ({0:?}) is absent in the certificate.")] LookupPathAbsent(Vec