Skip to main content

SseError

Enum SseError 

Source
#[non_exhaustive]
pub enum SseError<E> { Transport(E), InvalidUtf8(Utf8Error),
#[non_exhaustive]
EventTooLarge { limit: usize, }, }
Expand description

Why an SseStream (or an SseDecoder, with E = Infallible) failed.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Transport(E)

Reading the body failed: the body stream’s own error. Map it as you would any mid-stream transport failure (a TransportError keeps its kind, so a stream timeout stays a timeout).

§

InvalidUtf8(Utf8Error)

A line was not valid UTF-8.

The WHATWG event stream format decodes the stream as UTF-8 and replaces invalid bytes with U+FFFD. This decoder fails instead, on purpose. A browser shows event text to a person; an adapter decodes JSON from it, and a replaced byte changes a string value (generated text, tool arguments, an opaque signature that is replayed later) without anything saying so, which allama never does silently (ADR 0003). Invalid UTF-8 means a broken server or intermediary, and asking again streams the same bytes: map it to a stream decode error (allama::Error::stream_decode), which is not retryable, not to a transport failure. A chunk boundary inside a UTF-8 sequence is not an error: each line is decoded once it is complete.

§

#[non_exhaustive]
EventTooLarge

A line, or an event’s data, passed the decoder’s size cap (SseDecoder::max_event_size). The stream is not one the caller is prepared to hold, and asking again gets the same answer: map it to a stream protocol error (allama::Error::stream_protocol), not a retryable transport failure.

Fields

This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
§limit: usize

The cap, in bytes.

Implementations§

Source§

impl<E: Into<TransportError>> SseError<E>

Source

pub fn into_error(self) -> Error

The portable error for a failed SSE stream, as the variants say:

Neither of the last two is retryable, and every message is authored. Add the provider and the request id. SseChatStream::new maps failures with it.

use allama::{Error, StreamErrorKind};
use allama_http::sse::{SseError, SseStream};
use allama_http::{TransportError, TransportErrorKind};
use futures_util::{FutureExt, StreamExt, stream};

let body = stream::iter([Ok::<_, TransportError>(&b"data: \xFF\n\n"[..])]);
let failure = SseStream::new(body).next().now_or_never().flatten().unwrap().unwrap_err();
let err = failure.into_error().with_provider("acme");
assert!(matches!(err, Error::Stream { kind: StreamErrorKind::Decode, .. }));
assert!(!err.is_retryable());

let timeout = SseError::Transport(TransportError::new(TransportErrorKind::Timeout, "idle"));
assert!(matches!(timeout.into_error(), Error::Timeout { .. }));

Trait Implementations§

Source§

impl<E: Debug> Debug for SseError<E>

Source§

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

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

impl<E: Display> Display for SseError<E>

Source§

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

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

impl<E: Eq> Eq for SseError<E>

Source§

impl<E: Error + 'static> Error for SseError<E>

Source§

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

A transport failure is transparent: its source is the body error’s source.

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<E: Into<TransportError>> From<SseError<E>> for Error

Source§

fn from(error: SseError<E>) -> Self

The error SseError::into_error gives: what FramedChatStream::new classifies a failure with.

Source§

impl<E: PartialEq> PartialEq for SseError<E>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<E: PartialEq> StructuralPartialEq for SseError<E>

Auto Trait Implementations§

§

impl<E> Freeze for SseError<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for SseError<E>
where E: RefUnwindSafe,

§

impl<E> Send for SseError<E>
where E: Send,

§

impl<E> Sync for SseError<E>
where E: Sync,

§

impl<E> Unpin for SseError<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for SseError<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for SseError<E>
where E: UnwindSafe,

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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