pub enum ServerError {
Show 17 variants
MalformedJson(String),
EmptyMessages,
MultipleChoices {
n: u32,
},
UnsupportedContentPart {
kind: String,
},
MissingPartText,
InvalidToolName {
name: String,
param: &'static str,
},
UnsupportedToolChoice {
choice: String,
},
StopUnsupported,
ContextOverflow {
requested: usize,
limit: usize,
},
ModelLoading,
AtCapacity,
NotFound {
method: String,
path: String,
},
BodyTooLarge {
limit: usize,
},
Tokenizer(TokenizerError),
Generate(GenerateError),
Forward(ForwardError),
Serialize(Error),
}Expand description
Everything this crate can refuse to do.
Carries enough data to build the body without re-deriving it: an overflow
knows both numbers, a rejected content part knows its type.
Variants§
MalformedJson(String)
The body is not JSON, or not JSON of the expected shape. Carries serde’s message, which names the line, column and field.
EmptyMessages
messages was absent-but-defaulted or []. There is no prompt to
build, and rendering an empty conversation would make the model answer
from nothing at all.
MultipleChoices
n > 1. A single-session server has one decode loop; returning one
choice and calling it n would be a silent wrong answer, so it is
refused loudly instead.
UnsupportedContentPart
A content part this build cannot render, e.g. image_url.
Rejected rather than dropped: the pinned ChatML template coerces
non-string content to "", so silently discarding the part makes the
model answer a question it was never asked.
MissingPartText
A text content part with no text field.
InvalidToolName
A tool name outside the charset OpenAI itself constrains names to.
Validated and refused rather than sanitized, unlike message content. A name is not prose: the model echoes it back verbatim and the client matches the reply against the name it sent, so breaking a hostile name with a zero-width marker would produce a call nobody can match and a difference nobody can see in a log. Refusing the request is the only outcome the client can act on.
Fields
UnsupportedToolChoice
A tool_choice this build cannot honour: required, a named
function, or any value that is not auto or none.
The vendored template has no way to express “you must call a
function”: it branches on tools alone. Rendering the definitions and
letting the model choose freely would answer 200 to a request whose
central constraint was dropped.
StopUnsupported
A non-empty stop.
Accepted-and-ignored until now: nothing in the runtime consumes a stop string, so generation ran past where the caller asked it to end and the client had no way to tell. Refused until stop strings exist.
ContextOverflow
The prompt plus the reservation for the reply exceeds the context.
The message names the limit because a client that cannot see it has no way to trim the conversation to fit.
Fields
ModelLoading
The weights are still being opened. Transient; the same request will succeed once loading finishes.
AtCapacity
A generation is already in flight. Transient in exactly the same way, and reported the same way.
503, not 429. Retry behaviour is identical across the clients we care
about, but 429 makes openai-python raise RateLimitError, which
surfaces to a user as a quota or billing message — nonsense from a
server running on their own machine.
NotFound
No route serves this method and path.
A 404 with the same body shape as every other refusal, because a client pointed at the wrong base URL parses the error before it can report it, and an empty body or an HTML page turns “wrong path” into “the server is broken”.
Fields
BodyTooLarge
The request body is larger than this server will buffer.
The body is read into memory to be parsed, and this process is meant
to run inside a 3 GB cgroup alongside a model: an unbounded read is an
OOM with a Content-Length header for a trigger. The cap is generous
against a 4K context and small against the budget.
Tokenizer(TokenizerError)
Rendering or encoding the prompt failed.
Generate(GenerateError)
Generation failed inside the runtime.
Reported as a 500 rather than mapped onto a 400: every input-shaped
failure is caught before generation starts (see
ServerError::ContextOverflow and
ChatCompletionRequest::validate),
so anything that reaches here is this process’s problem.
Forward(ForwardError)
The KV cache could not be rewound to the prefix a request shares with
the one before it. Same reasoning as ServerError::Generate.
Serialize(Error)
A response could not be serialized. Unreachable for the types in this
crate (no maps with non-string keys, no failing Serialize impls);
reported rather than unwrapped so that stays true by construction.
Implementations§
Source§impl ServerError
impl ServerError
Sourcepub fn kind(&self) -> &'static str
pub fn kind(&self) -> &'static str
The error.type string.
404 and 413 join the 400s: all three say the client sent something
this server will not serve, which is what invalid_request_error
means to the SDKs that switch on it.
Sourcepub fn headers(&self) -> &'static [(&'static str, &'static str)]
pub fn headers(&self) -> &'static [(&'static str, &'static str)]
Headers to send alongside the body.
Both 503s get RETRY_HEADERS: loading and busy are the same promise
to the client — come back shortly and this will work.
Sourcepub fn body(&self) -> ErrorResponse
pub fn body(&self) -> ErrorResponse
The full error body.
Trait Implementations§
Source§impl Debug for ServerError
impl Debug for ServerError
Source§impl Display for ServerError
impl Display for ServerError
Source§impl Error for ServerError
impl Error for ServerError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<Error> for ServerError
impl From<Error> for ServerError
Source§impl From<ForwardError> for ServerError
impl From<ForwardError> for ServerError
Source§fn from(source: ForwardError) -> Self
fn from(source: ForwardError) -> Self
Source§impl From<GenerateError> for ServerError
impl From<GenerateError> for ServerError
Source§fn from(source: GenerateError) -> Self
fn from(source: GenerateError) -> Self
Source§impl From<TokenizerError> for ServerError
impl From<TokenizerError> for ServerError
Source§fn from(source: TokenizerError) -> Self
fn from(source: TokenizerError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for ServerError
impl !UnwindSafe for ServerError
impl Freeze for ServerError
impl Send for ServerError
impl Sync for ServerError
impl Unpin for ServerError
impl UnsafeUnpin for ServerError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more