From eddd241d84bcf2a7ffd1d2bd9d73ba12dba75257 Mon Sep 17 00:00:00 2001 From: Lucas Santana Date: Fri, 21 Aug 2026 16:05:53 -0300 Subject: [PATCH] fix(bot): stop reporting an outage when the fallbacks found nothing resolvePlayErrorMessage replaced any "no results found" error with "Music sources are currently unreachable" whenever the YouTube extractor was flagged degraded. It keyed only on that global flag plus a message regex, with nothing tying the error to the extractor that produced it. A text search does not stop at YouTube: resolveQueryWithFallbacks tries Spotify and SoundCloud after it. So a user searching a song that genuinely does not exist got told the sources were unreachable, when the healthy fallback engines had answered normally and correctly found nothing. Scopes the override to queries only the degraded extractor could have served, using the existing detectQueryType helper: a youtube.com/youtu.be URL cannot be served by Spotify or SoundCloud, so if YouTube is degraded that really is an outage for the user. A text search or a Spotify URL falling through to healthy engines is not. With no query supplied the two cases are indistinguishable, so it returns the accurate generic message instead of guessing an outage. Adds 3 cases, all failing before this change: text search that found nothing, spotify URL while youtube is degraded, and the no-query path. The original youtube case is kept and now passes a youtube URL. Closes #2000. --- .../play/handlers/playErrorMessage.spec.ts | 42 ++++++++++++++++++- .../play/handlers/playErrorMessage.ts | 24 ++++++++++- .../commands/play/handlers/playHandler.ts | 2 +- 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.spec.ts b/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.spec.ts index a867b7ccc..fdedc692e 100644 --- a/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.spec.ts +++ b/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.spec.ts @@ -21,12 +21,52 @@ describe('resolvePlayErrorMessage', () => { 'No results found for "some song" (Extractor: com.discord-player.youtube)', ) - expect(resolvePlayErrorMessage(error)).toBe( + expect( + resolvePlayErrorMessage( + error, + 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', + ), + ).toBe( 'Music sources are currently unreachable. Please try again in a few minutes.', ) expect(isExtractorDegradedMock).toHaveBeenCalledWith('youtube') }) + it('does not claim an outage for a text search that found nothing (#2000)', () => { + // A text search falls through to Spotify and SoundCloud. If it still + // finds nothing, the healthy engines answered correctly — saying + // "unreachable" reported an outage that did not happen. + isExtractorDegradedMock.mockReturnValue(true) + const error = new Error( + 'No results found for "asdkjhasd" (Extractor: com.discord-player.soundcloudextractor)', + ) + + expect(resolvePlayErrorMessage(error, 'asdkjhasd')).not.toBe( + 'Music sources are currently unreachable. Please try again in a few minutes.', + ) + }) + + it('does not claim an outage for a spotify url while youtube is degraded', () => { + isExtractorDegradedMock.mockReturnValue(true) + const error = new Error('No results found for "track"') + + expect( + resolvePlayErrorMessage( + error, + 'https://open.spotify.com/track/abc', + ), + ).not.toBe( + 'Music sources are currently unreachable. Please try again in a few minutes.', + ) + }) + + it('stays generic when no query is supplied rather than guessing an outage', () => { + isExtractorDegradedMock.mockReturnValue(true) + const error = new Error('No results found for "some song"') + + expect(resolvePlayErrorMessage(error)).toContain('No results found') + }) + it('falls back to the sanitized message for a no-results error when youtube is healthy', () => { isExtractorDegradedMock.mockReturnValue(false) const error = new Error('No results found for "some song"') diff --git a/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.ts b/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.ts index 71e80a1e1..360f5f040 100644 --- a/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.ts +++ b/packages/bot/src/functions/music/commands/play/handlers/playErrorMessage.ts @@ -1,13 +1,33 @@ import { createUserFriendlyError } from '@lucky/shared/utils/general/errorSanitizer' import { isExtractorDegraded } from '../../../../../handlers/player/extractorHealth' +import { detectQueryType } from '../queryDetector' // "No results found" is misleading when it's actually a degraded extractor // (e.g. YouTube session init silently failed but registration still // reported success) — say so instead (#1929). -export function resolvePlayErrorMessage(error: unknown): string { +// +// Scoped to queries only the degraded extractor could have served (#2000). +// A text search falls through resolveQueryWithFallbacks to Spotify and +// SoundCloud, so if it still finds nothing, the healthy engines answered and +// genuinely found nothing — calling that "unreachable" told users an outage +// had happened when the fallbacks had worked correctly. +export function resolvePlayErrorMessage( + error: unknown, + query?: string, +): string { const isNoResultsError = error instanceof Error && /no results found/i.test(error.message) - if (isNoResultsError && isExtractorDegraded('youtube')) { + + // Without a query we cannot tell the two cases apart, so fall back to the + // accurate generic message rather than guessing "outage". + const onlyYoutubeCouldServe = + query !== undefined && detectQueryType(query) === 'youtube' + + if ( + isNoResultsError && + onlyYoutubeCouldServe && + isExtractorDegraded('youtube') + ) { return 'Music sources are currently unreachable. Please try again in a few minutes.' } return createUserFriendlyError(error) diff --git a/packages/bot/src/functions/music/commands/play/handlers/playHandler.ts b/packages/bot/src/functions/music/commands/play/handlers/playHandler.ts index 11fd97de9..e6df69499 100644 --- a/packages/bot/src/functions/music/commands/play/handlers/playHandler.ts +++ b/packages/bot/src/functions/music/commands/play/handlers/playHandler.ts @@ -250,7 +250,7 @@ export async function executePlayHandler({ embeds: [ createErrorEmbed( 'Play Error', - resolvePlayErrorMessage(error), + resolvePlayErrorMessage(error, query), ), ], ephemeral: true,