Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Comment thread
LucasSantana-Dev marked this conversation as resolved.
Resolved
'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"')
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Comment thread
LucasSantana-Dev marked this conversation as resolved.
Resolved
Comment thread
LucasSantana-Dev marked this conversation as resolved.
Resolved
Comment thread
LucasSantana-Dev marked this conversation as resolved.
Resolved

if (
isNoResultsError &&
onlyYoutubeCouldServe &&
isExtractorDegraded('youtube')
) {
return 'Music sources are currently unreachable. Please try again in a few minutes.'
}
return createUserFriendlyError(error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export async function executePlayHandler({
embeds: [
createErrorEmbed(
'Play Error',
resolvePlayErrorMessage(error),
resolvePlayErrorMessage(error, query),
),
],
ephemeral: true,
Expand Down
Loading