Skip to content

Commit

Permalink
Turn empty images into error. Closes #8
Browse files Browse the repository at this point in the history
  • Loading branch information
NotNorom committed Sep 17, 2023
1 parent d957847 commit 4f91398
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/banner_changer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ impl ChangerError {
info!("Letting owner={guild_owner} of guild={guild_id} know about the missing banner feature");

dm_user(&ctx, guild_owner, &"Server has lost the required boost level. Stopping schedule. You can restart the bot after gaining the required boost level.").await?;
},
SetBannerError::ImageIsEmpty => {
warn!("guild_id={guild_id} with album={} has downloaded an image with 0 bytes", self.schedule.album());
}
},
err => {
Expand Down
6 changes: 3 additions & 3 deletions src/guild_id_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum SetBannerError {
CouldNotDeterminFileExtension,
#[error("Missing 'banner' feature")]
MissingBannerFeature,
#[error("Image is empty")]
ImageIsEmpty
}

#[async_trait]
Expand Down Expand Up @@ -88,10 +90,8 @@ impl RandomBanner for GuildId {
let amount_of_bytes = image_bytes.len();
debug!("Amount of image bytes downloaded: {}", amount_of_bytes);

// @todo proper error handling for this case.
// for now an early return will be enough
if amount_of_bytes == 0 {
return Ok(());
return Err(SetBannerError::ImageIsEmpty);
}

let b64 = base64::engine::general_purpose::STANDARD.encode(&image_bytes);
Expand Down

0 comments on commit 4f91398

Please sign in to comment.