pub struct StructuredError {
pub category: ErrorCategory,
pub message: String,
pub is_retryable: bool,
pub status_code: Option<u16>,
pub provider: Option<String>,
pub original_error: Option<String>,
pub token_count: Option<u64>,
pub token_limit: Option<u64>,
pub retry_after: Option<f64>,
}Expand description
Base structured error with metadata.
Fields§
§category: ErrorCategory§message: String§is_retryable: bool§status_code: Option<u16>§provider: Option<String>§original_error: Option<String>§token_count: Option<u64>For context overflow: how many tokens were in the prompt.
token_limit: Option<u64>For context overflow: what the model limit is.
retry_after: Option<f64>For rate limit: seconds to wait before retrying.
Implementations§
Source§impl StructuredError
impl StructuredError
Sourcepub fn should_compact(&self) -> bool
pub fn should_compact(&self) -> bool
Whether this error should trigger context compaction.
Sourcepub fn should_retry(&self) -> bool
pub fn should_retry(&self) -> bool
Whether the operation should be retried.
Sourcepub fn error_code(&self) -> &str
pub fn error_code(&self) -> &str
Return a stable error code for this error.
Error codes follow the pattern EXXXX_DESCRIPTION:
- E1xxx: Rate limiting and quota errors
- E2xxx: Tool and timeout errors
- E3xxx: Context and token errors
- E4xxx: Authentication and permission errors
- E5xxx: Gateway and network errors
- E9xxx: Unknown/unclassified errors
Sourcepub fn recovery_strategy(&self) -> RecoveryStrategy
pub fn recovery_strategy(&self) -> RecoveryStrategy
Return the recommended recovery strategy for this error.
Sourcepub fn api(message: impl Into<String>, status_code: Option<u16>) -> Self
pub fn api(message: impl Into<String>, status_code: Option<u16>) -> Self
Create a generic API error.
Sourcepub fn context_overflow(
message: impl Into<String>,
provider: Option<String>,
token_count: Option<u64>,
token_limit: Option<u64>,
) -> Self
pub fn context_overflow( message: impl Into<String>, provider: Option<String>, token_count: Option<u64>, token_limit: Option<u64>, ) -> Self
Create a context overflow error.
Sourcepub fn output_length(message: impl Into<String>) -> Self
pub fn output_length(message: impl Into<String>) -> Self
Create an output length error.
Sourcepub fn rate_limit(
message: impl Into<String>,
provider: Option<String>,
retry_after: Option<f64>,
) -> Self
pub fn rate_limit( message: impl Into<String>, provider: Option<String>, retry_after: Option<f64>, ) -> Self
Create a rate limit error.
Trait Implementations§
Source§impl Clone for StructuredError
impl Clone for StructuredError
Source§fn clone(&self) -> StructuredError
fn clone(&self) -> StructuredError
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StructuredError
impl Debug for StructuredError
Source§impl<'de> Deserialize<'de> for StructuredError
impl<'de> Deserialize<'de> for StructuredError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for StructuredError
impl Display for StructuredError
Source§impl Error for StructuredError
impl Error for StructuredError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for StructuredError
impl RefUnwindSafe for StructuredError
impl Send for StructuredError
impl Sync for StructuredError
impl Unpin for StructuredError
impl UnsafeUnpin for StructuredError
impl UnwindSafe for StructuredError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more