aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-localhttp / src / error.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | use std::time::Duration; |
| 17 | |
| 18 | /// Every way a request can fail. Each variant names one cause so callers and |
| 19 | /// tests can tell them apart. |
| 20 | #[derive(Debug, thiserror::Error)] |
| 21 | pub enum Error { |
| 22 | /// The URL uses `https://`. This client never speaks TLS and never |
| 23 | /// downgrades, so the request is refused before any connection is made. |
| 24 | #[error( |
| 25 | "https is refused for {url}: aien-localhttp speaks plain http to local services only and never downgrades; use the vetted TLS client for https" |
| 26 | )] |
| 27 | HttpsRefused { url: String }, |
| 28 | |
| 29 | /// The URL uses a scheme other than `http` or `https`. |
| 30 | #[error("unsupported URL scheme in {url}: only http:// is accepted")] |
| 31 | UnsupportedScheme { url: String }, |
| 32 | |
| 33 | /// The URL could not be parsed. |
| 34 | #[error("invalid URL {url:?}: {reason}")] |
| 35 | InvalidUrl { url: String, reason: &'static str }, |
| 36 | |
| 37 | /// A request header name or value was rejected. |
| 38 | #[error("invalid request header {name:?}: {reason}")] |
| 39 | InvalidHeader { name: String, reason: &'static str }, |
| 40 | |
| 41 | /// The JSON request body could not be encoded. |
| 42 | #[error("could not encode the JSON request body: {0}")] |
| 43 | Encode(String), |
| 44 | |
| 45 | /// Name resolution or the TCP connect failed. |
| 46 | #[error("connect to {addr} failed: {source}")] |
| 47 | Connect { |
| 48 | addr: String, |
| 49 | #[source] |
| 50 | source: std::io::Error, |
| 51 | }, |
| 52 | |
| 53 | /// The TCP connect did not finish within the connect timeout. |
| 54 | #[error("connect to {addr} timed out after {after:?}")] |
| 55 | ConnectTimeout { addr: String, after: Duration }, |
| 56 | |
| 57 | /// The total timeout ran out (request, response head or body). |
| 58 | #[error("request timed out after {0:?}")] |
| 59 | Timeout(Duration), |
| 60 | |
| 61 | /// A read or write on the connection failed. |
| 62 | #[error("i/o error: {0}")] |
| 63 | Io(#[from] std::io::Error), |
| 64 | |
| 65 | /// The response status line or headers break HTTP/1.1 framing rules. |
| 66 | #[error("malformed response: {0}")] |
| 67 | MalformedResponse(String), |
| 68 | |
| 69 | /// A chunk size line or chunk terminator is invalid. |
| 70 | #[error("malformed chunked body: {0}")] |
| 71 | MalformedChunk(String), |
| 72 | |
| 73 | /// The server closed the connection before the response was complete. |
| 74 | #[error("connection closed early: {0}")] |
| 75 | EarlyClose(String), |
| 76 | |
| 77 | /// The status line plus headers exceed the head size cap. |
| 78 | #[error("response head exceeds the {limit} byte cap")] |
| 79 | HeadTooLarge { limit: usize }, |
| 80 | |
| 81 | /// The body exceeds the body size cap. |
| 82 | #[error("response body exceeds the {limit} byte cap")] |
| 83 | BodyTooLarge { limit: usize }, |
| 84 | |
| 85 | /// The response body is not valid JSON for the requested type. |
| 86 | #[error("could not decode the JSON response body: {0}")] |
| 87 | Decode(String), |
| 88 | |
| 89 | /// The blocking entry point could not run its private runtime. |
| 90 | #[error("blocking request failed: {0}")] |
| 91 | Blocking(String), |
| 92 | } |
| 93 | |
| 94 | impl Error { |
| 95 | /// True for the connect timeout and the total timeout. |
| 96 | pub fn is_timeout(&self) -> bool { |
| 97 | matches!(self, Error::Timeout(_) | Error::ConnectTimeout { .. }) |
| 98 | } |
| 99 | |
| 100 | /// True when no connection could be made (resolution, refusal, connect timeout). |
| 101 | pub fn is_connect(&self) -> bool { |
| 102 | matches!(self, Error::Connect { .. } | Error::ConnectTimeout { .. }) |
| 103 | } |
| 104 | } |