From 7ce86010c2db5fddeb44e39b789a3c71e9a7f875 Mon Sep 17 00:00:00 2001 From: Steve McConnel Date: Thu, 28 Aug 2025 16:12:52 -0600 Subject: [PATCH] Fix crash during sorting due to wierd language tag (BL-15191) --- src/connection/sorting.ts | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/connection/sorting.ts b/src/connection/sorting.ts index 49fba97e..26b0a8d7 100644 --- a/src/connection/sorting.ts +++ b/src/connection/sorting.ts @@ -78,15 +78,29 @@ export function doExpensiveClientSideSortingIfNeeded( if (languageForSorting === "none") languageForSorting = undefined; - const comparator = new Intl.Collator( - languageForSorting /* it's ok if this is missing */, - { numeric: true } // will strip off leading 0's. - ); - const r = books.sort( - (a: IBookInfoForSorting, b: IBookInfoForSorting) => - comparator.compare(a.sortKey!, b.sortKey!) - ); - return r; + try { + const comparator = new Intl.Collator( + languageForSorting /* it's ok if this is missing */, + { numeric: true } // will strip off leading 0's. + ); + const r = books.sort( + (a: IBookInfoForSorting, b: IBookInfoForSorting) => + comparator.compare(a.sortKey!, b.sortKey!) + ); + return r; + } catch (e) { + console.error(`Error occurred during sorting: ${e}`); + console.error(`languageForSorting = "${languageForSorting}"`); + const comparator = new Intl.Collator( + undefined /* it's ok if this is missing */, + { numeric: true } // will strip off leading 0's. + ); + const r = books.sort( + (a: IBookInfoForSorting, b: IBookInfoForSorting) => + comparator.compare(a.sortKey!, b.sortKey!) + ); + return r; + } default: return books; // we already ordered them on the server }