diff options
| -rw-r--r-- | src/cache.gleam | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/cache.gleam b/src/cache.gleam index bc9144b..13c3b05 100644 --- a/src/cache.gleam +++ b/src/cache.gleam @@ -5,6 +5,7 @@ import gleam/option.{type Option} import gleam/result import image import simplifile +import wisp pub type CachedImage { CachedImage(data: BitArray, info: image.ImageInformation) @@ -17,7 +18,11 @@ pub fn load_themes() { list.fold( case simplifile.read_directory("./themes") { Ok(files) -> files - Error(_) -> [] + Error(_) -> { + wisp.log_error("Error reading themes directory") + + [] + } }, dict.new(), fn(accumulated_themes, theme) { @@ -26,19 +31,18 @@ pub fn load_themes() { theme, list.range(0, 9) |> list.fold(dict.new(), fn(accumulated_digits, digit) { - case - simplifile.read_bits( - from: "./themes/" - <> theme - <> "/" - <> int.to_string(digit) - <> "." - <> case theme { - "gelbooru-h" | "moebooru-h" | "lain" | "garukura" -> "png" - _ -> "gif" - }, - ) - { + let path = + "./themes/" + <> theme + <> "/" + <> int.to_string(digit) + <> "." + <> case theme { + "gelbooru-h" | "moebooru-h" | "lain" | "garukura" -> "png" + _ -> "gif" + } + + case simplifile.read_bits(from: path) { Ok(image_data) -> { case image.get_image_information(image_data) { Ok(info) -> @@ -47,10 +51,20 @@ pub fn load_themes() { digit, CachedImage(data: image_data, info: info), ) - Error(_) -> accumulated_digits + Error(_) -> { + wisp.log_error( + "Error getting image information for " <> path, + ) + + accumulated_digits + } } } - Error(_) -> accumulated_digits + Error(_) -> { + wisp.log_error("Error reading image file " <> path) + + accumulated_digits + } } }), ) |