Skip to content

Commit 2f1ae4d

Browse files
committed
feat(cache): Add error logs
1 parent 4649f7d commit 2f1ae4d

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/cache.gleam

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import gleam/option.{type Option}
55
import gleam/result
66
import image
77
import simplifile
8+
import wisp
89

910
pub type CachedImage {
1011
CachedImage(data: BitArray, info: image.ImageInformation)
@@ -17,7 +18,11 @@ pub fn load_themes() {
1718
list.fold(
1819
case simplifile.read_directory("./themes") {
1920
Ok(files) -> files
20-
Error(_) -> []
21+
Error(_) -> {
22+
wisp.log_error("Error reading themes directory")
23+
24+
[]
25+
}
2126
},
2227
dict.new(),
2328
fn(accumulated_themes, theme) {
@@ -26,19 +31,18 @@ pub fn load_themes() {
2631
theme,
2732
list.range(0, 9)
2833
|> list.fold(dict.new(), fn(accumulated_digits, digit) {
29-
case
30-
simplifile.read_bits(
31-
from: "./themes/"
32-
<> theme
33-
<> "/"
34-
<> int.to_string(digit)
35-
<> "."
36-
<> case theme {
37-
"gelbooru-h" | "moebooru-h" | "lain" | "garukura" -> "png"
38-
_ -> "gif"
39-
},
40-
)
41-
{
34+
let path =
35+
"./themes/"
36+
<> theme
37+
<> "/"
38+
<> int.to_string(digit)
39+
<> "."
40+
<> case theme {
41+
"gelbooru-h" | "moebooru-h" | "lain" | "garukura" -> "png"
42+
_ -> "gif"
43+
}
44+
45+
case simplifile.read_bits(from: path) {
4246
Ok(image_data) -> {
4347
case image.get_image_information(image_data) {
4448
Ok(info) ->
@@ -47,10 +51,20 @@ pub fn load_themes() {
4751
digit,
4852
CachedImage(data: image_data, info: info),
4953
)
50-
Error(_) -> accumulated_digits
54+
Error(_) -> {
55+
wisp.log_error(
56+
"Error getting image information for " <> path,
57+
)
58+
59+
accumulated_digits
60+
}
5161
}
5262
}
53-
Error(_) -> accumulated_digits
63+
Error(_) -> {
64+
wisp.log_error("Error reading image file " <> path)
65+
66+
accumulated_digits
67+
}
5468
}
5569
}),
5670
)

0 commit comments

Comments
 (0)