diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-10-02 20:35:34 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-10-02 20:35:34 -0300 |
commit | ca412ca52b1998fe715951309d3e0546560c2c58 (patch) | |
tree | 4629d6b9f2e96cee427a0a641fa4472bbb6f78f6 /src/data/checks.js | |
parent | bfc4a8cb5deb69d3692837f8ede95089a01bef44 (diff) |
data: Track.mainRelease, "Main Release: <album or track>"
Diffstat (limited to 'src/data/checks.js')
-rw-r--r-- | src/data/checks.js | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/src/data/checks.js b/src/data/checks.js index 5eba593b..edfd7e5b 100644 --- a/src/data/checks.js +++ b/src/data/checks.js @@ -237,7 +237,7 @@ export function filterReferenceErrors(wikiData, { sampledTracks: '_trackMainReleasesOnly', artTags: '_artTag', referencedArtworks: '_artwork', - mainReleaseTrack: '_trackMainReleasesOnly', + mainRelease: '_mainRelease', commentary: '_content', creditingSources: '_content', referencingSources: '_content', @@ -346,6 +346,55 @@ export function filterReferenceErrors(wikiData, { }; break; + case '_mainRelease': + findFn = ref => { + // Mocking what's going on in `withMainRelease`. + + let track, trackError; + let album, albumError; + + try { + track = boundFind.trackMainReleasesOnly(ref); + } catch (caughtError) { + trackError = new Error( + `Didn't match a track`, {cause: caughtError}); + } + + try { + album = boundFind.album(ref); + } catch (caughtError) { + albumError = new Error( + `Didn't match an album`, {cause: caughtError}); + } + + if (track && album) { + if (album.tracks.includes(track)) { + return track; + } else { + throw new Error( + `Unrelated album and track matched for reference "${ref}". Please resolve:\n` + + `- ${inspect(track)}\n` + + `- ${inspect(album)}\n` + + `Returning null for this reference.`); + } + } + + if (track ?? album) { + return track ?? album; + } + + const aggregateCause = + new AggregateError([albumError, trackError]); + + aggregateCause[Symbol.for('hsmusic.aggregate.translucent')] = true; + + throw new Error(`Trouble matching "${ref}"`, { + cause: aggregateCause, + }); + } + + break; + case '_trackArtwork': findFn = ref => boundFind.track(ref.reference); break; @@ -353,7 +402,7 @@ export function filterReferenceErrors(wikiData, { case '_trackMainReleasesOnly': findFn = trackRef => { const track = boundFind.track(trackRef); - const mainRef = track && CacheableObject.getUpdateValue(track, 'mainReleaseTrack'); + const mainRef = track && CacheableObject.getUpdateValue(track, 'mainRelease'); if (mainRef) { // It's possible for the main release to not actually exist, in this case. |