1use chrono::{DateTime, Utc};
2
3#[derive(Debug, thiserror::Error)]
4#[error("Provider '{provider}' hit API rate/usage limit")]
5pub struct LimitError {
6 pub provider: String,
7 pub reset_at: Option<DateTime<Utc>>,
8}
9
10#[derive(Debug, thiserror::Error)]
11#[error("seher '{label}' timed out after {ms}ms")]
12pub struct TimeoutError {
13 pub ms: u64,
14 pub label: &'static str,
15}
16
17#[derive(Debug, thiserror::Error)]
20pub enum RunError {
21 #[error("{error} (partial output: {} chars)", partial.len())]
22 Limit {
23 #[source]
24 error: LimitError,
25 partial: String,
26 },
27 #[error("{error} (partial output: {} chars)", partial.len())]
28 Timeout {
29 #[source]
30 error: TimeoutError,
31 partial: String,
32 },
33 #[error("{message} (partial output: {} chars)", partial.len())]
34 Other { message: String, partial: String },
35}
36
37impl RunError {
38 #[must_use]
40 pub fn partial(&self) -> &str {
41 match self {
42 Self::Limit { partial, .. }
43 | Self::Timeout { partial, .. }
44 | Self::Other { partial, .. } => partial,
45 }
46 }
47}