release: v0.1.10

This commit is contained in:
clawdbot committed 2026-11-02 01:14:53 +00:00
1 parent a289024b35
commit 1cae56fd3f
20 files changed
+163 -202

No files matched your search

+31 -8
View File
@@ -56,14 +56,14 @@ pub enum ApiError {
status: reqwest::StatusCode,
error_type: Option<String>,
message: Option<String>,
request_id: Option<String>,
request_id: Option<Box<str>>,
body: String,
retryable: bool,
/// Suggested user action based on error type (e.g., "Reduce prompt size" for 413)
suggested_action: Option<String>,
suggested_action: Option<&'static str>,
/// Parsed Retry-After header value (seconds) for 429 responses.
/// When present, overrides the exponential backoff delay.
retry_after: Option<Duration>,
retry_after: Option<Box<Duration>>,
},
RetriesExhausted {
attempts: u32,
@@ -137,7 +137,7 @@ impl ApiError {
/// over the computed backoff delay when it exists.
pub fn retry_after(&self) -> Option<Duration> {
match self {
Self::Api { retry_after, .. } => *retry_after,
Self::Api { retry_after, .. } => retry_after.as_deref().copied(),
Self::RetriesExhausted { last_error, .. } => last_error.retry_after(),
_ => None,
}
@@ -531,6 +531,29 @@ mod tests {
assert_eq!(snippet, "한글한글…");
}
#[test]
fn retry_after_survives_retry_exhaustion_wrapping() {
let delay = std::time::Duration::from_secs(42);
let error = ApiError::Api {
status: reqwest::StatusCode::TOO_MANY_REQUESTS,
error_type: None,
message: None,
request_id: Some("retry-trace".into()),
body: String::new(),
retryable: true,
suggested_action: Some("Wait before retrying"),
retry_after: Some(Box::new(delay)),
};
assert_eq!(error.retry_after(), Some(delay));
let wrapped = ApiError::RetriesExhausted {
attempts: 2,
last_error: Box::new(error),
};
assert_eq!(wrapped.retry_after(), Some(delay));
assert_eq!(wrapped.request_id(), Some("retry-trace"));
assert!(wrapped.is_retryable());
}
#[test]
fn detects_generic_fatal_wrapper_and_classifies_it_as_provider_internal() {
let error = ApiError::Api {
@@ -540,7 +563,7 @@ mod tests {
"Something went wrong while processing your request. Please try again, or use /new to start a fresh session."
.to_string(),
),
request_id: Some("req_jobdori_123".to_string()),
request_id: Some("req_jobdori_123".into()),
body: String::new(),
retryable: true,
suggested_action: None,
@@ -564,7 +587,7 @@ mod tests {
"Something went wrong while processing your request. Please try again, or use /new to start a fresh session."
.to_string(),
),
request_id: Some("req_nested_456".to_string()),
request_id: Some("req_nested_456".into()),
body: String::new(),
retryable: true,
suggested_action: None,
@@ -586,7 +609,7 @@ mod tests {
"This model's maximum context length is 200000 tokens, but your request used 230000 tokens."
.to_string(),
),
request_id: Some("req_ctx_123".to_string()),
request_id: Some("req_ctx_123".into()),
body: String::new(),
retryable: false,
suggested_action: None,
@@ -607,7 +630,7 @@ mod tests {
"Input tokens exceed the configured limit of 922000 tokens. Your messages resulted in 1860900 tokens. Please reduce the length of the messages."
.to_string(),
),
request_id: Some("req_ctx_openai_123".to_string()),
request_id: Some("req_ctx_openai_123".into()),
body: String::new(),
retryable: false,
suggested_action: None,
+3 -3
View File
@@ -886,11 +886,11 @@ async fn expect_success(response: reqwest::Response) -> Result<reqwest::Response
}
let headers = response.headers().clone();
let request_id = request_id_from_headers(&headers);
let request_id = request_id_from_headers(&headers).map(String::into_boxed_str);
let body = response.text().await.unwrap_or_else(|_| String::new());
let parsed_error = serde_json::from_str::<AnthropicErrorEnvelope>(&body).ok();
let retryable = is_retryable_status(status);
let retry_after = parse_retry_after(&headers, status);
let retry_after = parse_retry_after(&headers, status).map(Box::new);
Err(ApiError::Api {
status,
@@ -1651,7 +1651,7 @@ mod tests {
status: reqwest::StatusCode::UNAUTHORIZED,
error_type: Some("authentication_error".to_string()),
message: Some("Invalid bearer token".to_string()),
request_id: Some("req_varleg_001".to_string()),
request_id: Some("req_varleg_001".into()),
body: String::new(),
retryable: false,
suggested_action: None,
+12 -12
View File
@@ -261,7 +261,7 @@ impl OpenAiCompatClient {
.and_then(|t| t.as_str())
.map(str::to_owned),
message: Some(msg),
request_id,
request_id: request_id.map(String::into_boxed_str),
body,
retryable: false,
suggested_action: suggested_action_for_status(
@@ -1653,7 +1653,7 @@ fn parse_sse_frame(
request_id: None,
body: trimmed.chars().take(200).collect(),
retryable: false,
suggested_action: Some("verify the API endpoint URL is correct".to_string()),
suggested_action: Some("verify the API endpoint URL is correct"),
retry_after: None,
});
}
@@ -1706,7 +1706,7 @@ fn parse_sse_frame(
request_id: None,
body: payload.chars().take(200).collect(),
retryable: false,
suggested_action: Some("verify the API endpoint URL is correct".to_string()),
suggested_action: Some("verify the API endpoint URL is correct"),
retry_after: None,
});
}
@@ -1760,11 +1760,11 @@ async fn expect_success(response: reqwest::Response) -> Result<reqwest::Response
}
let headers = response.headers().clone();
let request_id = request_id_from_headers(&headers);
let request_id = request_id_from_headers(&headers).map(String::into_boxed_str);
let body = response.text().await.unwrap_or_default();
let parsed_error = serde_json::from_str::<ErrorEnvelope>(&body).ok();
let retryable = is_retryable_status(status);
let retry_after = parse_retry_after(&headers, status);
let retry_after = parse_retry_after(&headers, status).map(Box::new);
let suggested_action = suggested_action_for_status(status);
@@ -1819,14 +1819,14 @@ fn is_retryable_400(status: reqwest::StatusCode, body: &str) -> bool {
/// Generate a suggested user action based on the HTTP status code and error context.
/// This provides actionable guidance when API requests fail.
fn suggested_action_for_status(status: reqwest::StatusCode) -> Option<String> {
fn suggested_action_for_status(status: reqwest::StatusCode) -> Option<&'static str> {
match status.as_u16() {
401 => Some("Check API key is set correctly and has not expired".to_string()),
403 => Some("Verify API key has required permissions for this operation".to_string()),
413 => Some("Reduce prompt size or context window before retrying".to_string()),
429 => Some("Wait a moment before retrying; consider reducing request rate".to_string()),
500 => Some("Provider server error - retry after a brief wait".to_string()),
502..=504 => Some("Provider gateway error - retry after a brief wait".to_string()),
401 => Some("Check API key is set correctly and has not expired"),
403 => Some("Verify API key has required permissions for this operation"),
413 => Some("Reduce prompt size or context window before retrying"),
429 => Some("Wait a moment before retrying; consider reducing request rate"),
500 => Some("Provider server error - retry after a brief wait"),
502..=504 => Some("Provider gateway error - retry after a brief wait"),
_ => None,
}
}