🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
chore(server): add more info to scrobble errors logs (#3889)
Deluan Quintão5ab345c83ed8
diff --git a/core/agents/lastfm/agent.go b/core/agents/lastfm/agent.goindex 01ffa677e..0c8d290d4 100644--- a/core/agents/lastfm/agent.go+++ b/core/agents/lastfm/agent.go@@ -296,7 +296,7 @@ func (l *lastfmAgent) NowPlaying(ctx context.Context, userId string, track *mode})if err != nil {log.Warn(ctx, "Last.fm client.updateNowPlaying returned error", "track", track.Title, err)- return scrobbler.ErrUnrecoverable+ return errors.Join(err, scrobbler.ErrUnrecoverable)}return nil}@@ -304,7 +304,7 @@ func (l *lastfmAgent) NowPlaying(ctx context.Context, userId string, track *modefunc (l *lastfmAgent) Scrobble(ctx context.Context, userId string, s scrobbler.Scrobble) error {sk, err := l.sessionKeys.Get(ctx, userId)if err != nil || sk == "" {- return scrobbler.ErrNotAuthorized+ return errors.Join(err, scrobbler.ErrNotAuthorized)}if s.Duration <= 30 {@@ -328,12 +328,12 @@ func (l *lastfmAgent) Scrobble(ctx context.Context, userId string, s scrobbler.SisLastFMError := errors.As(err, &lfErr)if !isLastFMError {log.Warn(ctx, "Last.fm client.scrobble returned error", "track", s.Title, err)- return scrobbler.ErrRetryLater+ return errors.Join(err, scrobbler.ErrRetryLater)}if lfErr.Code == 11 || lfErr.Code == 16 {- return scrobbler.ErrRetryLater+ return errors.Join(err, scrobbler.ErrRetryLater)}- return scrobbler.ErrUnrecoverable+ return errors.Join(err, scrobbler.ErrUnrecoverable)}func (l *lastfmAgent) IsAuthorized(ctx context.Context, userId string) bool {diff --git a/core/agents/listenbrainz/agent.go b/core/agents/listenbrainz/agent.goindex e808f025e..200e9f63c 100644--- a/core/agents/listenbrainz/agent.go+++ b/core/agents/listenbrainz/agent.go@@ -76,14 +76,14 @@ func (l *listenBrainzAgent) formatListen(track *model.MediaFile) listenInfo {func (l *listenBrainzAgent) NowPlaying(ctx context.Context, userId string, track *model.MediaFile) error {sk, err := l.sessionKeys.Get(ctx, userId)if err != nil || sk == "" {- return scrobbler.ErrNotAuthorized+ return errors.Join(err, scrobbler.ErrNotAuthorized)}li := l.formatListen(track)err = l.client.updateNowPlaying(ctx, sk, li)if err != nil {log.Warn(ctx, "ListenBrainz updateNowPlaying returned error", "track", track.Title, err)- return scrobbler.ErrUnrecoverable+ return errors.Join(err, scrobbler.ErrUnrecoverable)}return nil}@@ -91,7 +91,7 @@ func (l *listenBrainzAgent) NowPlaying(ctx context.Context, userId string, trackfunc (l *listenBrainzAgent) Scrobble(ctx context.Context, userId string, s scrobbler.Scrobble) error {sk, err := l.sessionKeys.Get(ctx, userId)if err != nil || sk == "" {- return scrobbler.ErrNotAuthorized+ return errors.Join(err, scrobbler.ErrNotAuthorized)}li := l.formatListen(&s.MediaFile)@@ -105,12 +105,12 @@ func (l *listenBrainzAgent) Scrobble(ctx context.Context, userId string, s scrobisListenBrainzError := errors.As(err, &lbErr)if !isListenBrainzError {log.Warn(ctx, "ListenBrainz Scrobble returned HTTP error", "track", s.Title, err)- return scrobbler.ErrRetryLater+ return errors.Join(err, scrobbler.ErrRetryLater)}if lbErr.Code == 500 || lbErr.Code == 503 {- return scrobbler.ErrRetryLater+ return errors.Join(err, scrobbler.ErrRetryLater)}- return scrobbler.ErrUnrecoverable+ return errors.Join(err, scrobbler.ErrUnrecoverable)}func (l *listenBrainzAgent) IsAuthorized(ctx context.Context, userId string) bool {diff --git a/utils/cache/cached_http_client.go b/utils/cache/cached_http_client.goindex d570cb062..94d33100b 100644--- a/utils/cache/cached_http_client.go+++ b/utils/cache/cached_http_client.go@@ -49,16 +49,18 @@ func (c *HTTPClient) Do(req *http.Request) (*http.Response, error) {cached = falsereq, err := c.deserializeReq(key)if err != nil {+ log.Trace(req.Context(), "CachedHTTPClient.Do", "key", key, err)return "", 0, err}resp, err := c.hc.Do(req)if err != nil {+ log.Trace(req.Context(), "CachedHTTPClient.Do", "req", req, err)return "", 0, err}defer resp.Body.Close()return c.serializeResponse(resp), c.ttl, nil})- log.Trace(req.Context(), "CachedHTTPClient.Do", "key", key, "cached", cached, "elapsed", time.Since(start))+ log.Trace(req.Context(), "CachedHTTPClient.Do", "key", key, "cached", cached, "elapsed", time.Since(start), err)if err != nil {return nil, err}diff --git a/utils/cache/simple_cache.go b/utils/cache/simple_cache.goindex 595a26637..182d1d12a 100644--- a/utils/cache/simple_cache.go+++ b/utils/cache/simple_cache.go@@ -2,6 +2,7 @@ package cacheimport ("errors"+ "fmt""sync/atomic""time"@@ -74,10 +75,13 @@ func (c *simpleCache[K, V]) Get(key K) (V, error) {}func (c *simpleCache[K, V]) GetWithLoader(key K, loader func(key K) (V, time.Duration, error)) (V, error) {+ var err errorloaderWrapper := ttlcache.LoaderFunc[K, V](func(t *ttlcache.Cache[K, V], key K) *ttlcache.Item[K, V] {c.evictExpired()- value, ttl, err := loader(key)+ var value V+ var ttl time.Duration+ value, ttl, err = loader(key)if err != nil {return nil}@@ -87,6 +91,9 @@ func (c *simpleCache[K, V]) GetWithLoader(key K, loader func(key K) (V, time.Duritem := c.data.Get(key, ttlcache.WithLoader[K, V](loaderWrapper))if item == nil {var zero V+ if err != nil {+ return zero, fmt.Errorf("cache error: loader returned %w", err)+ }return zero, errors.New("item not found")}return item.Value(), nil