fix(lastfm): suppress expected "Track not found" (error 6) warnings from error channel

- Add isLastFmNotFound helper in lastfm constants
- Use logQueryWarning in TrackQueriesMixin, UserQueriesMixin, and ServerStatsMixin to handle uncataloged tracks gracefully
- Guard updateNowPlaying and scrobble from warning on missing Last.fm tracks
- Filter benign Last.fm 404 queries in ErrorChannel log forwarding
This commit is contained in:
NoLogicAlan committed 2026-11-14 01:57:24 +03:00
1 parent c9d932067e
commit 755efa5afd
6 files changed
+88 -40

No files matched your search

+2
View File
@@ -288,6 +288,8 @@ function _forward(level, tag, args) {
if (typeof tag !== "string") return; if (typeof tag !== "string") return;
if (tag.startsWith("[ErrorChannel]") || tag.startsWith("[Error_Handling]")) return; if (tag.startsWith("[ErrorChannel]") || tag.startsWith("[Error_Handling]")) return;
const body = _formatArgs(args); const body = _formatArgs(args);
/* Suppress expected external not-found lookups from generating alarmist telemetry warnings */
if (tag.includes("[LastFm]") && (/not found|error 6:/i.test(body) || /Track not found/i.test(body))) return;
const now = Date.now(); const now = Date.now();
const key = `${level}|${tag}|${(body || tag).slice(0, 200)}`; const key = `${level}|${tag}|${(body || tag).slice(0, 200)}`;
const last = _forwardDedup.get(key); const last = _forwardDedup.get(key);
+4 -2
View File
@@ -7,7 +7,7 @@
*/ */
import { logger } from "../../core/Logger.mjs"; import { logger } from "../../core/Logger.mjs";
import { apiCall, isLastFmFatalLinkError, isLastFmUserNotFound, noteStaleUser } from "./constants.mjs"; import { apiCall, isLastFmFatalLinkError, isLastFmUserNotFound, isLastFmNotFound, noteStaleUser } from "./constants.mjs";
/** /**
* @type {object} * @type {object}
@@ -48,6 +48,7 @@ const ScrobblingMixin = {
} }
return; return;
} }
if (isLastFmNotFound(err)) return;
logger.warn(`[LastFm] updateNowPlaying failed for ${userId}: ${err.message}`); logger.warn(`[LastFm] updateNowPlaying failed for ${userId}: ${err.message}`);
} }
}, },
@@ -89,6 +90,7 @@ const ScrobblingMixin = {
} }
return; return;
} }
if (isLastFmNotFound(err)) return;
logger.warn(`[LastFm] Scrobble failed for ${userId}: ${err.message}`); logger.warn(`[LastFm] Scrobble failed for ${userId}: ${err.message}`);
} }
}, },
@@ -124,7 +126,7 @@ const ScrobblingMixin = {
} }
return 0; return 0;
} }
if (!e?.message?.includes("fetch failed")) { if (!isLastFmNotFound(e) && !e?.message?.includes("fetch failed")) {
logger.warn("[LastFm] Error:", e?.message); logger.warn("[LastFm] Error:", e?.message);
} }
return 0; return 0;
+18 -8
View File
@@ -7,7 +7,17 @@
*/ */
import { logger } from "../../core/Logger.mjs"; import { logger } from "../../core/Logger.mjs";
import { isLastFmUserNotFound, noteStaleUser } from "./constants.mjs"; import { isLastFmUserNotFound, isLastFmNotFound, noteStaleUser } from "./constants.mjs";
/**
* @private
* Log failure only if it is an unexpected error, suppressing expected Last.fm not-found responses.
* @param {Error} e
*/
function logStatsWarning(e) {
if (isLastFmNotFound(e)) return;
logger.warn("[LastFm] Error:", e?.message);
}
/** /**
* @type {object} * @type {object}
@@ -51,7 +61,7 @@ const ServerStatsMixin = {
} }
return null; return null;
} }
logger.warn("[LastFm] Error:", e?.message); logStatsWarning(e);
return { return {
userId: uid, userId: uid,
username: user.username, username: user.username,
@@ -110,7 +120,7 @@ const ServerStatsMixin = {
} }
return null; return null;
} }
logger.warn("[LastFm] Error:", e?.message); logStatsWarning(e);
return { return {
userId: uid, userId: uid,
username: user.username, username: user.username,
@@ -169,7 +179,7 @@ const ServerStatsMixin = {
} }
return null; return null;
} }
logger.warn("[LastFm] Error:", e?.message); logStatsWarning(e);
return { return {
userId: uid, userId: uid,
username: user.username, username: user.username,
@@ -240,7 +250,7 @@ const ServerStatsMixin = {
matchPercentage, matchPercentage,
}; };
} catch (e) { } catch (e) {
logger.warn("[LastFm] Error:", e?.message); logStatsWarning(e);
return null; return null;
} }
}, },
@@ -340,7 +350,7 @@ const ServerStatsMixin = {
); );
return Number(rows[0]?.linked_users ?? 0); return Number(rows[0]?.linked_users ?? 0);
} catch (e) { } catch (e) {
logger.warn("[LastFm] Error:", e?.message); logStatsWarning(e);
return 0; return 0;
} }
}, },
@@ -506,7 +516,7 @@ const ServerStatsMixin = {
} }
return null; return null;
} }
logger.warn("[LastFm] Error:", e?.message); logStatsWarning(e);
return null; return null;
} }
}) })
@@ -586,7 +596,7 @@ const ServerStatsMixin = {
crowns.sort((a, b) => b.userPlaycount - a.userPlaycount); crowns.sort((a, b) => b.userPlaycount - a.userPlaycount);
return crowns; return crowns;
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logStatsWarning(e); return []; }
} }
}; };
+31 -21
View File
@@ -7,7 +7,17 @@
*/ */
import { logger } from "../../core/Logger.mjs"; import { logger } from "../../core/Logger.mjs";
import { apiCall, normalizeTrackText } from "./constants.mjs"; import { apiCall, normalizeTrackText, isLastFmNotFound } from "./constants.mjs";
/**
* @private
* Log query failure only if it is an unexpected error, suppressing expected Last.fm not-found responses.
* @param {Error} e
*/
function logQueryWarning(e) {
if (isLastFmNotFound(e)) return;
logger.warn("[LastFm] Error:", e?.message);
}
/** /**
* @type {object} * @type {object}
@@ -34,7 +44,7 @@ const TrackQueriesMixin = {
const data = await apiCall(params, this.apiSecret); const data = await apiCall(params, this.apiSecret);
return data.track; return data.track;
} catch (e) { } catch (e) {
logger.warn("[LastFm] Error:", e?.message); logQueryWarning(e);
return null; return null;
} }
}, },
@@ -226,7 +236,7 @@ const TrackQueriesMixin = {
url: t.url ?? "", url: t.url ?? "",
match: parseFloat(t.match ?? 0), match: parseFloat(t.match ?? 0),
})).filter(t => t.match > 0.1); })).filter(t => t.match > 0.1);
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -273,7 +283,7 @@ const TrackQueriesMixin = {
userplaycount: a.stats?.userplaycount ? Number(a.stats.userplaycount) : null, userplaycount: a.stats?.userplaycount ? Number(a.stats.userplaycount) : null,
}; };
} catch (e) { } catch (e) {
logger.warn("[LastFm] Error:", e?.message); logQueryWarning(e);
return null; return null;
} }
}, },
@@ -321,7 +331,7 @@ const TrackQueriesMixin = {
userplaycount: a.userplaycount ? Number(a.userplaycount) : null, userplaycount: a.userplaycount ? Number(a.userplaycount) : null,
}; };
} catch (e) { } catch (e) {
logger.warn("[LastFm] Error:", e?.message); logQueryWarning(e);
return null; return null;
} }
}, },
@@ -354,7 +364,7 @@ const TrackQueriesMixin = {
playcount: Number(t.playcount ?? 0), playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -385,7 +395,7 @@ const TrackQueriesMixin = {
playcount: Number(a.playcount ?? 0), playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -415,7 +425,7 @@ const TrackQueriesMixin = {
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
match: parseFloat(a.match ?? 0), match: parseFloat(a.match ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -448,7 +458,7 @@ const TrackQueriesMixin = {
summary: t.wiki?.summary ?? "", summary: t.wiki?.summary ?? "",
}; };
} catch (e) { } catch (e) {
logger.warn("[LastFm] Error:", e?.message); logQueryWarning(e);
return null; return null;
} }
}, },
@@ -481,7 +491,7 @@ const TrackQueriesMixin = {
playcount: Number(t.playcount ?? 0), playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -511,7 +521,7 @@ const TrackQueriesMixin = {
playcount: Number(a.playcount ?? 0), playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -548,7 +558,7 @@ const TrackQueriesMixin = {
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
listeners: Number(a.listeners ?? 0), listeners: Number(a.listeners ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -585,7 +595,7 @@ const TrackQueriesMixin = {
url: a.url ?? "", url: a.url ?? "",
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -609,7 +619,7 @@ const TrackQueriesMixin = {
url: t.url ?? "", url: t.url ?? "",
count: Number(t.count ?? 0), count: Number(t.count ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -635,7 +645,7 @@ const TrackQueriesMixin = {
url: t.url ?? "", url: t.url ?? "",
count: Number(t.count ?? 0), count: Number(t.count ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -661,7 +671,7 @@ const TrackQueriesMixin = {
url: t.url ?? "", url: t.url ?? "",
count: Number(t.count ?? 0), count: Number(t.count ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -687,7 +697,7 @@ const TrackQueriesMixin = {
playcount: Number(a.playcount ?? 0), playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -712,7 +722,7 @@ const TrackQueriesMixin = {
listeners: Number(a.listeners ?? 0), listeners: Number(a.listeners ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -738,7 +748,7 @@ const TrackQueriesMixin = {
listeners: Number(t.listeners ?? 0), listeners: Number(t.listeners ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -763,7 +773,7 @@ const TrackQueriesMixin = {
playcount: Number(t.playcount ?? 0), playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -787,7 +797,7 @@ const TrackQueriesMixin = {
playcount: Number(a.playcount ?? 0), playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
} }
}; };
+18 -8
View File
@@ -7,7 +7,17 @@
*/ */
import { logger } from "../../core/Logger.mjs"; import { logger } from "../../core/Logger.mjs";
import { apiCall } from "./constants.mjs"; import { apiCall, isLastFmNotFound } from "./constants.mjs";
/**
* @private
* Log query failure only if it is an unexpected error, suppressing expected Last.fm not-found responses.
* @param {Error} e
*/
function logQueryWarning(e) {
if (isLastFmNotFound(e)) return;
logger.warn("[LastFm] Error:", e?.message);
}
/** /**
* @type {object} * @type {object}
@@ -115,7 +125,7 @@ const UserQueriesMixin = {
url: t.url ?? "", url: t.url ?? "",
count: Number(t.count ?? 0), count: Number(t.count ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -144,7 +154,7 @@ const UserQueriesMixin = {
from: Number(c.from ?? 0), from: Number(c.from ?? 0),
to: Number(c.to ?? 0), to: Number(c.to ?? 0),
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -442,7 +452,7 @@ const UserQueriesMixin = {
query: `${t.name} ${t.artist ?? ar.name}`, query: `${t.name} ${t.artist ?? ar.name}`,
image: t.image ?? ar.image ?? "", image: t.image ?? ar.image ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}) })
); );
for (const r of artistResults) { for (const r of artistResults) {
@@ -495,7 +505,7 @@ const UserQueriesMixin = {
realname: f.realname ?? "", realname: f.realname ?? "",
country: f.country ?? "", country: f.country ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -525,7 +535,7 @@ const UserQueriesMixin = {
playcount: Number(a.playcount ?? 0), playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -556,7 +566,7 @@ const UserQueriesMixin = {
playcount: Number(t.playcount ?? 0), playcount: Number(t.playcount ?? 0),
image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "", image: t.image?.[2]?.["#text"] ?? t.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
}, },
/** /**
@@ -587,7 +597,7 @@ const UserQueriesMixin = {
playcount: Number(a.playcount ?? 0), playcount: Number(a.playcount ?? 0),
image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "", image: a.image?.[2]?.["#text"] ?? a.image?.[1]?.["#text"] ?? "",
})); }));
} catch (e) { logger.warn("[LastFm] Error:", e?.message); return []; } } catch (e) { logQueryWarning(e); return []; }
} }
}; };
+15 -1
View File
@@ -63,6 +63,20 @@ function isLastFmUserNotFound(err) {
return /user not found/i.test(String(err?.message ?? "")); return /user not found/i.test(String(err?.message ?? ""));
} }
/**
* Check whether a Last.fm error is an expected "Not Found" response (track, artist, album, tag, or user not found, code 6).
* Common when querying streams, YouTube videos, or uncataloged tracks that do not exist in Last.fm's database.
* @param {Error|object} err
* @returns {boolean}
*/
function isLastFmNotFound(err) {
if (!err) return false;
const msg = String(err?.message ?? err ?? "");
const code = Number(err?.code) || 0;
return code === 6
|| /track not found|artist not found|album not found|user not found|tag not found|could not be found/i.test(msg);
}
/** /**
* Check whether an error means the stored Last.fm link is unrecoverable — * Check whether an error means the stored Last.fm link is unrecoverable —
* the linked account no longer exists or its session was revoked. Deliberately * the linked account no longer exists or its session was revoked. Deliberately
@@ -164,4 +178,4 @@ async function apiCall(params, apiSecret, post = false) {
return data; return data;
} }
export { BASE_URL, normalizeTrackText, buildSignature, apiCall, LastFmApiError, isLastFmUserNotFound, isLastFmFatalLinkError, noteStaleUser, clearStaleUserFlag }; export { BASE_URL, normalizeTrackText, buildSignature, apiCall, LastFmApiError, isLastFmUserNotFound, isLastFmNotFound, isLastFmFatalLinkError, noteStaleUser, clearStaleUserFlag };