aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-01 04:15:47 -0700
committerFuwn <[email protected]>2025-07-01 04:15:47 -0700
commit2f1ae4da3228a3e098b519d20db603872611e667 (patch)
treef7d9dbaca61db4bd65e303e0cfb86319f73440b0 /src
parent4649f7d0f1851593539d6233bb59f1b40f092548 (diff)
downloadmayu-2f1ae4da3228a3e098b519d20db603872611e667.tar.xz
mayu-2f1ae4da3228a3e098b519d20db603872611e667.zip
feat(cache): Add error logs
Diffstat (limited to 'src')
-rw-r--r--src/cache.gleam46
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
+ }
}
}),
)