#[non_exhaustive]pub enum NdjsonError<E> {
Transport(E),
InvalidUtf8(Utf8Error),
#[non_exhaustive] LineTooLarge {
limit: usize,
},
}Expand description
Why an NdjsonStream (or an NdjsonDecoder, with E =
Infallible) failed.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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. JSON text is UTF-8, and a replaced byte
would change a value 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. A chunk boundary inside a UTF-8 sequence is not an error:
each line is decoded once it is complete.
#[non_exhaustive]LineTooLarge
A line passed the framer’s size cap
(NdjsonDecoder::max_line_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.
Implementations§
Source§impl<E: Into<TransportError>> NdjsonError<E>
impl<E: Into<TransportError>> NdjsonError<E>
Sourcepub fn into_error(self) -> Error
pub fn into_error(self) -> Error
The portable error for a failed NDJSON stream, as the variants say:
Transport: the body error as aTransportError, mapped byTransportError::into_stream_error, so a stream timeout staysallama::Error::Timeoutand any other failed read is a retryable transport stream error;InvalidUtf8: a stream decode error;LineTooLarge: a stream protocol error.
Neither of the last two is retryable, and every message is
authored. Add the provider and the request
id. FramedChatStream::new
maps failures with it.
use allama::{Error, StreamErrorKind};
use allama_http::TransportError;
use allama_http::ndjson::NdjsonStream;
use futures_util::{FutureExt, StreamExt, stream};
let body = stream::iter([Ok::<_, TransportError>(&b"{\"a\":\"\xFF\"}\n"[..])]);
let failure = NdjsonStream::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());Trait Implementations§
Source§impl<E: Debug> Debug for NdjsonError<E>
impl<E: Debug> Debug for NdjsonError<E>
Source§impl<E: Display> Display for NdjsonError<E>
impl<E: Display> Display for NdjsonError<E>
impl<E: Eq> Eq for NdjsonError<E>
Source§impl<E: Error + 'static> Error for NdjsonError<E>
impl<E: Error + 'static> Error for NdjsonError<E>
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl<E: Into<TransportError>> From<NdjsonError<E>> for Error
impl<E: Into<TransportError>> From<NdjsonError<E>> for Error
Source§fn from(error: NdjsonError<E>) -> Self
fn from(error: NdjsonError<E>) -> Self
The error NdjsonError::into_error gives: what
FramedChatStream::new
classifies a failure with.
Source§impl<E: PartialEq> PartialEq for NdjsonError<E>
impl<E: PartialEq> PartialEq for NdjsonError<E>
impl<E: PartialEq> StructuralPartialEq for NdjsonError<E>
Auto Trait Implementations§
impl<E> Freeze for NdjsonError<E>where
E: Freeze,
impl<E> RefUnwindSafe for NdjsonError<E>where
E: RefUnwindSafe,
impl<E> Send for NdjsonError<E>where
E: Send,
impl<E> Sync for NdjsonError<E>where
E: Sync,
impl<E> Unpin for NdjsonError<E>where
E: Unpin,
impl<E> UnsafeUnpin for NdjsonError<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for NdjsonError<E>where
E: UnwindSafe,
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
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> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.