Sfoglia il codice sorgente

fix(icon): improve logging messages in resizeIcon function

Frédéric Guillot 7 mesi fa
parent
commit
fdc12bf18c
1 ha cambiato i file con 7 aggiunte e 6 eliminazioni
  1. 7 6
      internal/reader/icon/finder.go

+ 7 - 6
internal/reader/icon/finder.go

@@ -203,13 +203,13 @@ func resizeIcon(icon *model.Icon) *model.Icon {
 		// minifier.Bytes returns the data unchanged in case of error.
 		icon.Content, err = minifier.Bytes("image/svg+xml", icon.Content)
 		if err != nil {
-			slog.Error("Unable to minimize the svg file", slog.Any("error", err))
+			slog.Error("Unable to minify SVG icon", slog.Any("error", err))
 		}
 		return icon
 	}
 
 	if !slices.Contains([]string{"image/jpeg", "image/png", "image/gif", "image/webp"}, icon.MimeType) {
-		slog.Info("icon isn't a png/gif/jpeg/webp, can't resize", slog.String("mimetype", icon.MimeType))
+		slog.Info("Icon resize skipped: unsupported MIME type", slog.String("mime_type", icon.MimeType))
 		return icon
 	}
 
@@ -218,11 +218,11 @@ func resizeIcon(icon *model.Icon) *model.Icon {
 	// Don't resize icons that we can't decode, or that already have the right size.
 	config, _, err := image.DecodeConfig(r)
 	if err != nil {
-		slog.Warn("unable to decode the metadata of the icon", slog.Any("error", err))
+		slog.Warn("Unable to decode icon metadata", slog.Any("error", err))
 		return icon
 	}
 	if config.Height <= 32 && config.Width <= 32 {
-		slog.Debug("icon don't need to be rescaled", slog.Int("height", config.Height), slog.Int("width", config.Width))
+		slog.Debug("Icon doesn't need to be resized", slog.Int("height", config.Height), slog.Int("width", config.Width))
 		return icon
 	}
 
@@ -240,7 +240,7 @@ func resizeIcon(icon *model.Icon) *model.Icon {
 		src, err = webp.Decode(r)
 	}
 	if err != nil || src == nil {
-		slog.Warn("unable to decode the icon", slog.Any("error", err))
+		slog.Warn("Unable to decode icon image", slog.Any("error", err))
 		return icon
 	}
 
@@ -249,7 +249,8 @@ func resizeIcon(icon *model.Icon) *model.Icon {
 
 	var b bytes.Buffer
 	if err = png.Encode(io.Writer(&b), dst); err != nil {
-		slog.Warn("unable to encode the new icon", slog.Any("error", err))
+		slog.Warn("Unable to encode resized icon", slog.Any("error", err))
+		return icon
 	}
 
 	icon.Content = b.Bytes()