Skip to content

fix(applemusic): handle tracks without albumName - #833

Merged
FoxxMD merged 1 commit into
FoxxMD:masterfrom
jseiden12:fix/applemusic-missing-album-825
Dec 5, 2026
Merged

FoxxMD merged 1 commit into
FoxxMD:masterfrom
jseiden12:fix/applemusic-missing-album-825

Conversation

@jseiden12

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Describe your changes

AppleMusicSource.formatPlayObj called .replace() on track.albumName without checking that it exists. One recently-played track with no album failed the whole poll, and after the maximum number of retries the source stopped polling.

The replace now uses optional chaining, so such a track produces a play with data.album undefined. Albums that are present are normalized as before.

node-musickit-api types albumName as a required string, so the compiler does not flag this. The other track fields read in formatPlayObj (artistName, name, isrc, durationInMillis, url) are not dereferenced there, so they did not need a change.

Testing, on Node 24:

  • Added a test for a track without albumName, with normalizeAlbum both on and off. Without the fix it fails with TypeError: Cannot read properties of undefined (reading 'replace').
  • Backend mocha suite: 1496 passing, 1 failing (the new test), 30 pending before the fix; 1497 passing, 30 pending after.
  • tsc -p src/backend --noEmit passes.
  • oxlint on the two changed files reports warnings only. The new test uses as any like the existing mock tracks in that file.

This was not tested against the live Apple Music API.

Issue number and link, if applicable

Fixes #825

This PR was prepared with AI assistance (Claude) and reviewed before submission.

🤖 Generated with Claude Code

The recently-played history can return a track with no albumName, and
formatPlayObj called .replace() on it when album normalization was
enabled (the default). The TypeError failed the whole poll until the
source stopped polling.

Only normalize the album name when it is present. A track without one
now results in a play with no album.

Fixes FoxxMD#825

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Dec 5, 2026

Copy link
Copy Markdown

👷 Deploy request for multi-scrobbler pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 43f6add

@FoxxMD
FoxxMD merged commit 6ccd0bb into FoxxMD:master Dec 5, 2026
@FoxxMD

FoxxMD commented Dec 5, 2026

Copy link
Copy Markdown
Owner

@Exerra

node-musickit-api types albumName as a required string, so the compiler does not flag this.

Could be worth doing a patch update to correct this typing!

@jseiden12
jseiden12 deleted the fix/applemusic-missing-album-825 branch December 5, 2026 19:00
@Exerra

Exerra commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Could be worth doing a patch update to correct this typing!

Probably should but I still want to get the song or track that was responsible for that beforehand...

My best guess is it is a library song, which (if I understand correctly) can be a locally imported song without any kind of metadata. Everything in the Apple Music catalogue should have an album name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Apple Music source stops polling when a recently-played track has no albumName (formatPlayObj .replace on undefined)

3 participants