Skip to content

Commit f2363d6

Browse files
authored
Merge pull request #591 from StephenMcConnel/BL-15191-BloomLibraryCrash
Fix crash during sorting due to wierd language tag (BL-15191) (#591)
2 parents 728eae5 + 7ce8601 commit f2363d6

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

src/connection/sorting.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,29 @@ export function doExpensiveClientSideSortingIfNeeded(
7878

7979
if (languageForSorting === "none") languageForSorting = undefined;
8080

81-
const comparator = new Intl.Collator(
82-
languageForSorting /* it's ok if this is missing */,
83-
{ numeric: true } // will strip off leading 0's.
84-
);
85-
const r = books.sort(
86-
(a: IBookInfoForSorting, b: IBookInfoForSorting) =>
87-
comparator.compare(a.sortKey!, b.sortKey!)
88-
);
89-
return r;
81+
try {
82+
const comparator = new Intl.Collator(
83+
languageForSorting /* it's ok if this is missing */,
84+
{ numeric: true } // will strip off leading 0's.
85+
);
86+
const r = books.sort(
87+
(a: IBookInfoForSorting, b: IBookInfoForSorting) =>
88+
comparator.compare(a.sortKey!, b.sortKey!)
89+
);
90+
return r;
91+
} catch (e) {
92+
console.error(`Error occurred during sorting: ${e}`);
93+
console.error(`languageForSorting = "${languageForSorting}"`);
94+
const comparator = new Intl.Collator(
95+
undefined /* it's ok if this is missing */,
96+
{ numeric: true } // will strip off leading 0's.
97+
);
98+
const r = books.sort(
99+
(a: IBookInfoForSorting, b: IBookInfoForSorting) =>
100+
comparator.compare(a.sortKey!, b.sortKey!)
101+
);
102+
return r;
103+
}
90104
default:
91105
return books; // we already ordered them on the server
92106
}

0 commit comments

Comments
 (0)