Skip to main content

ServerError

Enum ServerError 

Source
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.

Fields

§n: u32

What the client asked for.

§

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.

Fields

§kind: String

The part’s type field, verbatim.

§

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

§name: String

The offending name, verbatim, so a client can find it.

§param: &'static str

Which request field carried it: tools for a definition, messages for a call echoed back on an assistant turn.

§

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.

Fields

§choice: String

What the client asked for, as JSON.

§

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

§requested: usize

Prompt tokens plus the tokens reserved for the reply.

§limit: usize

The context cap this server was started with.

§

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

§method: String

The request method, verbatim.

§path: String

The request path, query string stripped.

§

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.

Fields

§limit: usize

The cap, in bytes.

§

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

Source

pub fn status(&self) -> u16

The HTTP status for this error.

Source

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.

Source

pub fn param(&self) -> Option<&'static str>

The request field at fault, when one can be named.

Source

pub fn code(&self) -> &'static str

The stable machine-readable code.

Source

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.

Source

pub fn body(&self) -> ErrorResponse

The full error body.

Source

pub fn body_json(&self) -> String

The full error body, serialized. Falls back to a hand-built body if serialization somehow fails, so an error path can never panic and can never return something without a message.

Trait Implementations§

Source§

impl Debug for ServerError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ServerError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for ServerError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for ServerError

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ForwardError> for ServerError

Source§

fn from(source: ForwardError) -> Self

Converts to this type from the input type.
Source§

impl From<GenerateError> for ServerError

Source§

fn from(source: GenerateError) -> Self

Converts to this type from the input type.
Source§

impl From<TokenizerError> for ServerError

Source§

fn from(source: TokenizerError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more