openkind_engine/error.rs
1//! Errors and Result alias for engine operations and dispatch.
2
3use openkind_core::ValidationError;
4use thiserror::Error;
5
6/// Errors that can occur during engine execution or model dispatch.
7///
8/// These errors are translated into corresponding HTTP/gRPC status codes by the API layer.
9#[derive(Debug, Error)]
10pub enum EngineError {
11 /// Request body failed schema validation. Mapped to HTTP 422 Unprocessable Entity.
12 #[error("invalid request: {0}")]
13 Invalid(#[from] ValidationError),
14
15 /// Requested model alias is not registered. Mapped to HTTP 404 Not Found.
16 #[error("no backend registered for model `{0}`")]
17 UnknownModel(String),
18
19 /// Request is valid Jev but unsupported by the selected backend profile. Mapped to HTTP 422.
20 #[error("backend `{backend}` does not support this request: {message}")]
21 Unsupported {
22 /// Identifier of the selected backend.
23 backend: String,
24 /// Contract limitation that rejected the request.
25 message: String,
26 },
27
28 /// Backend admission queue is full. Mapped to HTTP 529 / gRPC unavailable.
29 #[error("backend `{backend}` is overloaded; retry after {retry_after_ms} ms")]
30 Overloaded {
31 /// Identifier of the selected backend.
32 backend: String,
33 /// Suggested caller backoff.
34 retry_after_ms: u64,
35 },
36
37 /// Queue-inclusive evaluation deadline elapsed. Mapped to HTTP 504 / gRPC deadline exceeded.
38 #[error("backend `{backend}` evaluation exceeded its {timeout_ms} ms deadline")]
39 DeadlineExceeded {
40 /// Identifier of the selected backend.
41 backend: String,
42 /// Configured end-to-end queue and execution budget.
43 timeout_ms: u64,
44 },
45
46 /// Underlying backend driver encountered an internal execution failure. Mapped to HTTP 500.
47 #[error("backend `{backend}` failed: {message}")]
48 Backend {
49 /// Identifier of the failing backend.
50 backend: String,
51 /// Descriptive failure message.
52 message: String,
53 },
54}
55
56/// Specialized Result alias for engine operations returning an [`EngineError`].
57pub type EngineResult<T> = Result<T, EngineError>;