agentkit_provider_cerebras/
error.rs1use agentkit_core::ItemKind;
4use agentkit_http::HttpError;
5use agentkit_loop::LoopError;
6use thiserror::Error;
7
8use crate::config::PartKindName;
9
10#[derive(Debug, Error)]
12pub enum CerebrasError {
13 #[error(transparent)]
15 Build(#[from] BuildError),
16
17 #[error("missing or invalid environment variable {0}")]
19 MissingEnv(&'static str),
20
21 #[error("Cerebras request failed with status {status}: {body}")]
23 Status {
24 status: u16,
26 body: String,
28 },
29
30 #[error(transparent)]
32 Http(#[from] HttpError),
33
34 #[error(transparent)]
36 Response(#[from] ResponseError),
37
38 #[error("{0}")]
40 Other(String),
41}
42
43impl From<CerebrasError> for LoopError {
44 fn from(error: CerebrasError) -> Self {
45 match error {
46 CerebrasError::Other(msg) => LoopError::Provider(msg),
47 other => LoopError::Provider(other.to_string()),
48 }
49 }
50}
51
52#[derive(Debug, Error)]
54pub enum BuildError {
55 #[error("unsupported content part {part_kind:?} on role {role:?}")]
58 UnsupportedPart {
59 role: ItemKind,
61 part_kind: PartKindName,
63 },
64
65 #[error("tool name {0:?} does not match ^[a-zA-Z0-9_-]{{1,64}}$")]
67 InvalidToolName(String),
68
69 #[error("response_format schema violates Cerebras constraint: {0}")]
72 SchemaViolation(String),
73
74 #[error("prediction cannot be combined with {0}")]
76 PredictionConflicts(&'static str),
77
78 #[error("{field} out of range: {message}")]
80 OutOfRange {
81 field: &'static str,
83 message: String,
85 },
86
87 #[error("missing or invalid environment variable {0}")]
89 MissingEnv(&'static str),
90
91 #[error("top_logprobs requires logprobs = true")]
93 TopLogprobsWithoutLogprobs,
94
95 #[error(transparent)]
97 Serialize(#[from] serde_json::Error),
98}
99
100impl From<BuildError> for LoopError {
101 fn from(error: BuildError) -> Self {
102 LoopError::Provider(error.to_string())
103 }
104}
105
106#[derive(Debug, Error)]
108pub enum ResponseError {
109 #[error("protocol error: {0}")]
112 Protocol(String),
113
114 #[error("stream error ({status_code:?}): {message}")]
117 StreamError {
118 message: String,
120 status_code: Option<u16>,
122 },
123}
124
125impl From<ResponseError> for LoopError {
126 fn from(error: ResponseError) -> Self {
127 LoopError::Provider(error.to_string())
128 }
129}