artificial_core/error.rs
1//! Unified error type exposed by **`artificial-core`**.
2//!
3//! Provider crates should convert their internal errors into one of these
4//! variants before bubbling them up to the [`ArtificialClient`]. This keeps
5//! the public API small while still conveying rich diagnostic information.
6
7use thiserror::Error;
8
9/// Convenient alias used throughout the workspace.
10pub type Result<T> = std::result::Result<T, ArtificialError>;
11
12#[derive(Debug, Error)]
13pub enum ArtificialError {
14 /// A prompt targeted a provider (`provider_id`) for which no backend has
15 /// been registered in the [`ArtificialClient`].
16 #[error("backend for provider `{provider}` is not configured")]
17 BackendNotConfigured { provider: &'static str },
18
19 /// The selected backend is present but does not recognise or support the
20 /// requested `model`.
21 #[error("provider `{provider}` does not support model `{model}`")]
22 ModelNotSupported {
23 provider: &'static str,
24 model: &'static str,
25 },
26
27 /// Failure while serialising or deserialising JSON payloads sent to / received
28 /// from the LLM provider.
29 #[error("serialization error: {0}")]
30 Serialization(#[from] serde_json::Error),
31
32 /// Generic forwarding of any backend-specific error that doesn’t fit another
33 /// category.
34 #[error("backend returned an error: {0}")]
35 Backend(Box<dyn std::error::Error + Send + Sync + 'static>),
36
37 #[error("invalid request: {0}")]
38 InvalidRequest(String),
39
40 #[error("invalid: {0}")]
41 Invalid(String),
42}