Better error handling

This commit is contained in:
Deluan
2022-12-28 10:19:52 -05:00
committed by Deluan Quintão
parent 949331ed24
commit bc09de6640
8 changed files with 37 additions and 43 deletions
+4 -5
View File
@@ -19,20 +19,19 @@ import (
"github.com/navidrome/navidrome/resources"
)
func extractImage(ctx context.Context, artID model.ArtworkID, extractFuncs ...sourceFunc) (io.ReadCloser, string) {
func selectImageReader(ctx context.Context, artID model.ArtworkID, extractFuncs ...sourceFunc) (io.ReadCloser, string, error) {
for _, f := range extractFuncs {
if ctx.Err() != nil {
return nil, ""
return nil, "", ctx.Err()
}
r, path, err := f()
if r != nil {
log.Trace(ctx, "Found artwork", "artID", artID, "path", path, "source", f)
return r, path
return r, path, nil
}
log.Trace(ctx, "Tried to extract artwork", "artID", artID, "source", f, err)
}
log.Error(ctx, "extractImage should never reach this point!", "artID", artID, "path")
return nil, ""
return nil, "", fmt.Errorf("could not get a cover art for %s", artID)
}
type sourceFunc func() (r io.ReadCloser, path string, err error)