Skip to main content

supercode_runtime/
error.rs

1//! Errors produced by the optional native model runtime.
2
3use thiserror::Error;
4
5/// Result type for native runtime operations.
6pub type Result<T> = std::result::Result<T, RuntimeError>;
7
8/// A provider-transport or response error.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum RuntimeError {
12    /// The HTTP transport failed.
13    #[error("http transport error: {0}")]
14    Http(#[source] Box<dyn std::error::Error + Send + Sync>),
15
16    /// The provider returned a non-success status.
17    #[error("provider returned status {status}: {body}")]
18    Provider {
19        /// HTTP status code.
20        status: u16,
21        /// Raw response body, truncated before construction when necessary.
22        body: String,
23    },
24
25    /// A provider response could not be decoded.
26    #[error("failed to decode provider response: {0}")]
27    Decode(#[from] serde_json::Error),
28}
29
30impl From<reqwest::Error> for RuntimeError {
31    fn from(error: reqwest::Error) -> Self {
32        Self::Http(Box::new(error))
33    }
34}