Compare commits

...
2 Commits
Author SHA1 Message Date
NoLogicAlan 923f9f2ce3 hotfix 2026-09-25 01:27:53 +03:00
NoLogicAlan 1f11239376 fix: surface previously-silent persistence errors in Settings.mjs and Player.mjs 2026-09-25 01:16:28 +03:00
7 changed files with 47 additions and 16 deletions

No files matched your search

+1 -1
View File
@@ -448,10 +448,10 @@ export class CommandHandler extends EventEmitter {
const authorId = msg.message?.author?.id; const authorId = msg.message?.author?.id;
const isOwner = this.owners.includes(authorId); const isOwner = this.owners.includes(authorId);
const permGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId; const permGuildId = msg.channel?.channel?.guildId ?? msg.message?.guildId;
if (!isOwner && cmd.requirements.some(r => r.ownerOnly)) return false;
for (let i = 0; i < cmd.requirements.length; i++) { for (let i = 0; i < cmd.requirements.length; i++) {
let req = cmd.requirements[i]; let req = cmd.requirements[i];
if (req.ownerOnly && !isOwner) return false;
if (req.permissions.length > 0 && !isOwner) { if (req.permissions.length > 0 && !isOwner) {
const guild = msg.message?.guild ?? null; const guild = msg.message?.guild ?? null;
if (!guild) { if (!guild) {
+7 -2
View File
@@ -24,11 +24,16 @@ export class PrefixManager {
} }
/** /**
* Get the command prefix for a guild. * Get the command prefix for a guild. DMs and any other context without a
* @param {string} guildId * real guildId skip the settings lookup entirely — falling through to
* getServer(undefined) would create and permanently cache a phantom
* "undefined" guild entry in the settings store, which then shows up in
* every guilds-map iteration (24/7 watchdog, shutdown save-all, etc.).
* @param {string|null|undefined} guildId
* @returns {string} * @returns {string}
*/ */
getPrefix(guildId) { getPrefix(guildId) {
if (!guildId) return this.configPrefix ?? "%";
const serverPrefix = this.settings.getServer(guildId).get("prefix"); const serverPrefix = this.settings.getServer(guildId).get("prefix");
return serverPrefix ?? this.configPrefix ?? "%"; return serverPrefix ?? this.configPrefix ?? "%";
} }
+5 -1
View File
@@ -486,7 +486,11 @@ export class RemoteSettingsManager extends SettingsManager {
this._debounceTimers.set(server.id, setTimeout(() => { this._debounceTimers.set(server.id, setTimeout(() => {
this._debounceTimers.delete(server.id); this._debounceTimers.delete(server.id);
const target = this.guilds.get(server.id); const target = this.guilds.get(server.id);
if (target) this.remoteUpdate(target, key); if (target) {
this.remoteUpdate(target, key).catch(e =>
logger.error(`[Settings] debounced update error (guild ${server.id}, key "${key}"):`, e?.message)
);
}
}, 80)); }, 80));
} }
+25 -4
View File
@@ -24,6 +24,27 @@ import PlaybackMixin from "./PlaybackMixin.mjs";
import SearchMixin from "./SearchMixin.mjs"; import SearchMixin from "./SearchMixin.mjs";
import DisplayMixin from "./DisplayMixin.mjs"; import DisplayMixin from "./DisplayMixin.mjs";
/** @type {number} Timestamp (ms) of the last logged player-state persistence failure. */
let _lastPersistErrorLog = 0;
/** @type {number} Minimum spacing between persistence-error log lines, to avoid log floods when MySQL is down/unreachable. */
const PERSIST_ERROR_LOG_COOLDOWN_MS = 60_000;
/**
* Log a player-state persistence failure (saveSnapshot / updatePosition),
* rate-limited so a prolonged DB outage doesn't spam the log for every
* player's debounce/heartbeat tick. Persistence is best-effort — playback
* must never be interrupted by it — but a silent, permanently-swallowed
* failure previously left operators with zero visibility when it broke.
* @param {string} where - Short tag identifying the call site.
* @param {Error} e - The error thrown/rejected by the store call.
*/
function logPersistError(where, e) {
const now = Date.now();
if (now - _lastPersistErrorLog < PERSIST_ERROR_LOG_COOLDOWN_MS) return;
_lastPersistErrorLog = now;
logger.warn(`[Player] State persistence (${where}) failed — resume/queue restore may be stale until this clears (will not re-log for 60s):`, e?.message ?? e);
}
/** /**
* @class Player * @class Player
* @description Main music player class. Manages voice connections, playback, * @description Main music player class. Manages voice connections, playback,
@@ -164,8 +185,8 @@ class Player extends EventEmitter {
this._snapSaveTimer = setTimeout(() => { this._snapSaveTimer = setTimeout(() => {
this._snapSaveTimer = null; this._snapSaveTimer = null;
try { try {
this.client?._remix?.playerState?.saveSnapshot(this)?.catch?.(() => {}); this.client?._remix?.playerState?.saveSnapshot(this)?.catch?.(e => logPersistError("saveSnapshot", e));
} catch (_) { /* persistence must never break playback */ } } catch (e) { logPersistError("saveSnapshot/sync", e); }
}, 3_000); }, 3_000);
}; };
for (const evt of ["queue", "startplay", "stopplay", "playback"]) { for (const evt of ["queue", "startplay", "stopplay", "playback"]) {
@@ -177,8 +198,8 @@ class Player extends EventEmitter {
if (!current || this._destroyed || this.leaving || this._paused) return; if (!current || this._destroyed || this.leaving || this._paused) return;
if (!this.startedPlaying) return; if (!this.startedPlaying) return;
const pos = Math.max(0, Date.now() - this.startedPlaying); const pos = Math.max(0, Date.now() - this.startedPlaying);
this.client?._remix?.playerState?.updatePosition?.(this._guildId, pos)?.catch?.(() => {}); this.client?._remix?.playerState?.updatePosition?.(this._guildId, pos)?.catch?.(e => logPersistError("updatePosition", e));
} catch (_) { /* best effort */ } } catch (e) { logPersistError("updatePosition/sync", e); }
}, 15_000); }, 15_000);
this._stateHeartbeat.unref?.(); this._stateHeartbeat.unref?.();
+2 -2
View File
@@ -5,7 +5,7 @@
* used by every command. * used by every command.
*/ */
import { Client, Events, EmbedBuilder, PermissionFlags } from "@fluxerjs/core"; import { Client, Events, EmbedBuilder, PermissionFlags, ErrorCodes } from "@fluxerjs/core";
import { logger } from "../core/Logger.mjs"; import { logger } from "../core/Logger.mjs";
import { Utils } from "../utils/Utils.mjs"; import { Utils } from "../utils/Utils.mjs";
import { Message, Channel } from "./Wrappers.mjs"; import { Message, Channel } from "./Wrappers.mjs";
@@ -498,7 +498,7 @@ export class MessageHandler {
try { try {
return new Message(await message.edit(payload), this); return new Message(await message.edit(payload), this);
} catch (err) { } catch (err) {
if (err.code === "UNKNOWN_MESSAGE" || err.code === 10008) { if (err.code === ErrorCodes.MessageNotFound || String(err?.message ?? "").includes("Message wasn't found")) {
logger.warn("[MessageHandler] editEmbed: Message no longer exists, skipping edit."); logger.warn("[MessageHandler] editEmbed: Message no longer exists, skipping edit.");
return null; return null;
} }
+5 -5
View File
@@ -5,7 +5,7 @@
* (two-arrow embed paging). * (two-arrow embed paging).
*/ */
import { EmbedBuilder } from "@fluxerjs/core"; import { EmbedBuilder, ErrorCodes } from "@fluxerjs/core";
import { logger } from "../core/Logger.mjs"; import { logger } from "../core/Logger.mjs";
import { Message } from "./Wrappers.mjs"; import { Message } from "./Wrappers.mjs";
import { getGlobalColor } from "./Embeds.mjs"; import { getGlobalColor } from "./Embeds.mjs";
@@ -248,14 +248,14 @@ export class RichPaginator {
await rawMsg.removeAllReactions(); await rawMsg.removeAllReactions();
return; return;
} catch (e) { } catch (e) {
if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === 10008) return; if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === ErrorCodes.MessageNotFound) return;
logger.warn("[RichPaginator] removeAllReactions failed:", e?.message ?? e); logger.warn("[RichPaginator] removeAllReactions failed:", e?.message ?? e);
} }
for (const emoji of allReactions) { for (const emoji of allReactions) {
try { try {
await rawMsg.removeReaction(emoji); await rawMsg.removeReaction(emoji);
} catch(e) { } catch(e) {
if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === 10008) return; if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === ErrorCodes.MessageNotFound) return;
logger.warn("[MessageHandler] Error:", e?.message); logger.warn("[MessageHandler] Error:", e?.message);
} }
} }
@@ -346,12 +346,12 @@ export class QueuePaginator {
try { try {
await rawMsg.removeAllReactions(); await rawMsg.removeAllReactions();
} catch (e) { } catch (e) {
if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === 10008) return; if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === ErrorCodes.MessageNotFound) return;
for (const emoji of [prev, next]) { for (const emoji of [prev, next]) {
try { try {
await rawMsg.removeReaction(emoji); await rawMsg.removeReaction(emoji);
} catch(e) { } catch(e) {
if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === 10008) return; if (String(e?.message ?? e).includes("Message wasn't found") || e?.code === ErrorCodes.MessageNotFound) return;
logger.warn("[MessageHandler] Error:", e?.message); logger.warn("[MessageHandler] Error:", e?.message);
} }
} }
+2 -1
View File
@@ -23,6 +23,7 @@
import { logger } from "../../core/Logger.mjs"; import { logger } from "../../core/Logger.mjs";
import { cleanId } from "../../utils/Utils.mjs"; import { cleanId } from "../../utils/Utils.mjs";
import { get247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager } from "../../utils/Helpers247.mjs"; import { get247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager } from "../../utils/Helpers247.mjs";
import { ErrorCodes } from "@fluxerjs/core";
/** @type {number} Default sweep interval (ms). Overridable via config.timers.watchdog247Interval. */ /** @type {number} Default sweep interval (ms). Overridable via config.timers.watchdog247Interval. */
const DEFAULT_SWEEP_INTERVAL = 60_000; const DEFAULT_SWEEP_INTERVAL = 60_000;
@@ -99,7 +100,7 @@ const Watchdog247 = {
if (fetched) return { channel: fetched, definitive: false }; if (fetched) return { channel: fetched, definitive: false };
return { channel: null, definitive: true }; return { channel: null, definitive: true };
} catch (err) { } catch (err) {
const gone = err?.code === "CHANNEL_NOT_FOUND" const gone = err?.code === ErrorCodes.ChannelNotFound
|| err?.statusCode === 404 || err?.status === 404 || err?.statusCode === 404 || err?.status === 404
|| /\b404\b|not found|unknown channel/i.test(String(err?.message ?? "")); || /\b404\b|not found|unknown channel/i.test(String(err?.message ?? ""));
return { channel: null, definitive: gone }; return { channel: null, definitive: gone };