mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
update memory input stream errors handler
This commit is contained in:
parent
3a9e84a3d9
commit
239786da6a
6 changed files with 27 additions and 12 deletions
|
|
@ -111,7 +111,7 @@ pub fn read_all_from_stream_async(
|
||||||
// Continue bytes reading
|
// Continue bytes reading
|
||||||
read_all_from_stream_async(buffer, stream, cancelable, priority, callback);
|
read_all_from_stream_async(buffer, stream, cancelable, priority, callback);
|
||||||
}
|
}
|
||||||
Err(reason) => callback(Err(Error::InputStreamRead(reason))),
|
Err(reason) => callback(Err(Error::InputStream(reason))),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter, Result};
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
BufferOverflow,
|
BufferOverflow,
|
||||||
Decode(std::string::FromUtf8Error),
|
Decode(std::string::FromUtf8Error),
|
||||||
InputStreamRead(glib::Error),
|
InputStream(glib::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
impl Display for Error {
|
||||||
|
|
@ -16,7 +16,7 @@ impl Display for Error {
|
||||||
Self::Decode(reason) => {
|
Self::Decode(reason) => {
|
||||||
write!(f, "Decode error: {reason}")
|
write!(f, "Decode error: {reason}")
|
||||||
}
|
}
|
||||||
Self::InputStreamRead(reason) => {
|
Self::InputStream(reason) => {
|
||||||
write!(f, "Input stream read error: {reason}")
|
write!(f, "Input stream read error: {reason}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ pub fn read_from_stream_async(
|
||||||
// Continue
|
// Continue
|
||||||
read_from_stream_async(buffer, stream, cancellable, priority, on_complete);
|
read_from_stream_async(buffer, stream, cancellable, priority, on_complete);
|
||||||
}
|
}
|
||||||
Err((data, reason)) => on_complete(Err(Error::InputStreamRead(data, reason))),
|
Err((data, reason)) => on_complete(Err(Error::InputStream(data, reason))),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use std::fmt::{Display, Formatter, Result};
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Data(super::data::Error),
|
Data(super::data::Error),
|
||||||
InputStreamRead(Vec<u8>, glib::Error),
|
InputStream(Vec<u8>, glib::Error),
|
||||||
Mime(super::mime::Error),
|
Mime(super::mime::Error),
|
||||||
Protocol,
|
Protocol,
|
||||||
Status(super::status::Error),
|
Status(super::status::Error),
|
||||||
|
|
@ -15,7 +15,7 @@ impl Display for Error {
|
||||||
Self::Data(reason) => {
|
Self::Data(reason) => {
|
||||||
write!(f, "Data error: {reason}")
|
write!(f, "Data error: {reason}")
|
||||||
}
|
}
|
||||||
Self::InputStreamRead(_, reason) => {
|
Self::InputStream(_, reason) => {
|
||||||
// @TODO
|
// @TODO
|
||||||
write!(f, "Input stream error: {reason}")
|
write!(f, "Input stream error: {reason}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ pub fn from_stream_async(
|
||||||
bytes_in_chunk: usize,
|
bytes_in_chunk: usize,
|
||||||
bytes_total_limit: usize,
|
bytes_total_limit: usize,
|
||||||
on_chunk: impl Fn((Bytes, usize)) + 'static,
|
on_chunk: impl Fn((Bytes, usize)) + 'static,
|
||||||
on_complete: impl FnOnce(Result<MemoryInputStream, (Error, Option<&str>)>) + 'static,
|
on_complete: impl FnOnce(Result<MemoryInputStream, Error>) + 'static,
|
||||||
) {
|
) {
|
||||||
read_all_from_stream_async(
|
read_all_from_stream_async(
|
||||||
MemoryInputStream::new(),
|
MemoryInputStream::new(),
|
||||||
|
|
@ -43,7 +43,7 @@ pub fn read_all_from_stream_async(
|
||||||
bytes: (usize, usize, usize),
|
bytes: (usize, usize, usize),
|
||||||
callback: (
|
callback: (
|
||||||
impl Fn((Bytes, usize)) + 'static,
|
impl Fn((Bytes, usize)) + 'static,
|
||||||
impl FnOnce(Result<MemoryInputStream, (Error, Option<&str>)>) + 'static,
|
impl FnOnce(Result<MemoryInputStream, Error>) + 'static,
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
let (on_chunk, on_complete) = callback;
|
let (on_chunk, on_complete) = callback;
|
||||||
|
|
@ -63,7 +63,7 @@ pub fn read_all_from_stream_async(
|
||||||
|
|
||||||
// Validate max size
|
// Validate max size
|
||||||
if bytes_total > bytes_total_limit {
|
if bytes_total > bytes_total_limit {
|
||||||
return on_complete(Err((Error::BytesTotal, None)));
|
return on_complete(Err(Error::BytesTotal(bytes_total, bytes_total_limit)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// No bytes were read, end of stream
|
// No bytes were read, end of stream
|
||||||
|
|
@ -85,7 +85,7 @@ pub fn read_all_from_stream_async(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(reason) => {
|
Err(reason) => {
|
||||||
on_complete(Err((Error::InputStream, Some(reason.message()))));
|
on_complete(Err(Error::InputStream(reason)));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,20 @@
|
||||||
|
use std::fmt::{Display, Formatter, Result};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
BytesTotal,
|
BytesTotal(usize, usize),
|
||||||
InputStream,
|
InputStream(glib::Error),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Error {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||||
|
match self {
|
||||||
|
Self::BytesTotal(total, limit) => {
|
||||||
|
write!(f, "Bytes total limit reached: {total} / {limit}")
|
||||||
|
}
|
||||||
|
Self::InputStream(reason) => {
|
||||||
|
write!(f, "Input stream error: {reason}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue