From bf42300e76241a2df888dc458c59a7478a8b2d61 Mon Sep 17 00:00:00 2001 From: HiDeoo <494699+HiDeoo@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:31:03 +0100 Subject: [PATCH] Stop silencing i18n content collection related errors (#2546) --- .changeset/big-ducks-rhyme.md | 5 +++++ packages/starlight/utils/translations.ts | 12 ++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 .changeset/big-ducks-rhyme.md diff --git a/.changeset/big-ducks-rhyme.md b/.changeset/big-ducks-rhyme.md new file mode 100644 index 00000000000..f73e10c068d --- /dev/null +++ b/.changeset/big-ducks-rhyme.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Fixes an issue where i18n content collection related errors, e.g. malformed JSON or YAML, would not be reported. diff --git a/packages/starlight/utils/translations.ts b/packages/starlight/utils/translations.ts index 3c9827c91b5..468cd724874 100644 --- a/packages/starlight/utils/translations.ts +++ b/packages/starlight/utils/translations.ts @@ -14,17 +14,13 @@ export type UserI18nKeys = keyof RemoveIndexSignature; /** Get all translation data from the i18n collection, keyed by `id`, which matches locale. */ async function loadTranslations() { - let userTranslations: Record = {}; // Briefly override `console.warn()` to silence logging when a project has no i18n collection. const warn = console.warn; console.warn = () => {}; - try { - // Load the user’s i18n collection and ignore the error if it doesn’t exist. - userTranslations = Object.fromEntries( - // @ts-ignore — may be an error in projects without an i18n collection - (await getCollection('i18n')).map(({ id, data }) => [id, data] as const) - ); - } catch {} + const userTranslations: Record = Object.fromEntries( + // @ts-ignore — may be a type error in projects without an i18n collection + (await getCollection('i18n')).map(({ id, data }) => [id, data] as const) + ); // Restore the original warn implementation. console.warn = warn; return userTranslations;