Add explicit error handling to image loading

This commit is contained in:
Héctor Ramón Jiménez 2025-10-28 21:19:25 +01:00
parent 7c11ccb046
commit 867fe819c0
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
17 changed files with 357 additions and 118 deletions

View file

@ -166,7 +166,7 @@ pub enum Error {
RequestFailed(Arc<reqwest::Error>),
IOFailed(Arc<io::Error>),
JoinFailed(Arc<task::JoinError>),
ImageDecodingFailed(Arc<image::ImageError>),
ImageDecodingFailed,
BlurhashDecodingFailed(Arc<blurhash::Error>),
}
@ -188,12 +188,6 @@ impl From<task::JoinError> for Error {
}
}
impl From<image::ImageError> for Error {
fn from(error: image::ImageError) -> Self {
Self::ImageDecodingFailed(Arc::new(error))
}
}
impl From<blurhash::Error> for Error {
fn from(error: blurhash::Error) -> Self {
Self::BlurhashDecodingFailed(Arc::new(error))

View file

@ -49,7 +49,7 @@ enum Message {
ImagePoppedOut(Id),
ImageDownloaded(Result<image::Allocation, Error>),
ThumbnailDownloaded(Id, Result<Bytes, Error>),
ThumbnailAllocated(Id, image::Allocation),
ThumbnailAllocated(Id, Result<image::Allocation, image::Error>),
ThumbnailHovered(Id, bool),
BlurhashDecoded(Id, civitai::Blurhash),
Open(Id),
@ -175,7 +175,7 @@ impl Gallery {
.then(image::allocate)
.map(Message::ThumbnailAllocated.with(id))
}
Message::ThumbnailAllocated(id, allocation) => {
Message::ThumbnailAllocated(id, Ok(allocation)) => {
if !self.visible.contains(&id) {
return Task::none();
}
@ -221,7 +221,7 @@ impl Gallery {
Task::future(image.download(Size::Original))
.and_then(|bytes| {
image::allocate(image::Handle::from_bytes(bytes))
.map(Ok)
.map_err(|_| Error::ImageDecodingFailed)
})
.map(Message::ImageDownloaded)
}
@ -236,6 +236,11 @@ impl Gallery {
| Message::ThumbnailDownloaded(_, Err(error)) => {
dbg!(error);
Task::none()
}
Message::ThumbnailAllocated(_, Err(error)) => {
dbg!(error);
Task::none()
}
}