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

@ -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()
}
}